Hightower Posted April 27, 2009 Posted April 27, 2009 Can somebody tell me why this isn't working: Private Sub cmdBookAdd_Click() Dim iCounter As Integer If iCounter = 0 Then cmdBookAdd.Caption = "Save" rsBook.AddNew SetBookText iCounter = 1 Else cmdBookAdd.Caption = "Add" SetBookData rsBook.Update iCounter = 0 End If End Sub I want it to add a new record, but it doesn't work - anything obvious?
Hightower Posted April 27, 2009 Author Posted April 27, 2009 Private Sub SetBookText() Dim iCounter As Integer For iCounter = 0 To 6 'If the recordset is NOT empty then put it in the box If rsBook(iCounter) <> "" Then txtBook(iCounter).Text = rsBook(iCounter) 'Else the text box is set to blank Else txtBook(iCounter).Text = "" End If Next iCounter End Sub Private Sub SetBookData() 'This function puts new data into the book table Dim iCounter As Integer For iCounter = 0 To 6 rsBook(iCounter) = txtBook(iCounter).Text Next iCounter End Sub Sorry - might be useful if I include the private functions it calls.
mac_shinobi Posted April 27, 2009 Posted April 27, 2009 Private Sub cmdBookAdd_Click() Dim iCounter As Integer iCounter = 0 ' <--- This was not set to 0 to initialise it If iCounter = 0 Then cmdBookAdd.Caption = "Save" rsBook.AddNew SetBookText iCounter = 1 Else cmdBookAdd.Caption = "Add" SetBookData rsBook.Update iCounter = 0 End If End Sub Not sure if setting iCounter to zero to start with will help
Hightower Posted April 27, 2009 Author Posted April 27, 2009 Private Sub cmdBookAdd_Click() Dim iCounter As Integer iCounter = 0 ' <--- This was not set to 0 to initialise it If iCounter = 0 Then cmdBookAdd.Caption = "Save" rsBook.AddNew SetBookText iCounter = 1 Else cmdBookAdd.Caption = "Add" SetBookData rsBook.Update iCounter = 0 End If End Sub Not sure if setting iCounter to zero to start with will help No, that wasn't it - but it did prompt me to check something. I hadn't defined the variable as a static so each time it was forgetting what value it was holding. The solution was to change: Dim iCounter As Integer to... Static iCounter As Integer Tested it and it works fine now. Thanks
mac_shinobi Posted April 27, 2009 Posted April 27, 2009 (edited) No, that wasn't it - but it did prompt me to check something. I hadn't defined the variable as a static so each time it was forgetting what value it was holding. The solution was to change: Dim iCounter As Integer to... Static iCounter As Integer Tested it and it works fine now. Thanks your welcome - haven't done or used vb6 for a long time now so its a very rusty subject for me now lol Edited April 27, 2009 by mac_shinobi
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now