Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have created a project (Reference Library) using VB6 and Access 2000. The VB front end consists of two forms, Title Form and Copy Form. The following code is run at ‘Form Activate’ and is situated on the Title Form.
The problem I am having is as a complete novice I am unsure of the code I have begged from exercises I have done on evening classes. The majority of the code is working for the functionsProblem: I go to the Copy form to delete a copy from the database which works fine. I then go back to the Title Form but am faced with an error code and ‘Record is Deleted’ this is because the line below:
If DatCopy.Recordset.Fields("ISBN") = TxtISBN.Text Then
Is activated with the form (the code counts No of Copies and displays to form).
Is there an ‘Else’ or a line of code that will stop this error occurring. I need for the Title form to realise that the copy no longer exists and update accordingly.
Also anybody know if there is a way to reset an access database as I have added and removed that may records that my first record is now numbered something like 24.
Regards
M
DatCopy.Recordset.MoveFirst
' WHile not at the end of the Copy table
While Not DatCopy.Recordset.EOF
' If the ISBN in the DatCopy table matches the one in the Text Box
If DatCopy.Recordset.Fields("ISBN") = TxtISBN.Text Then
' Add 1 to the number of copies
numOfCopies = numOfCopies + 1
End If
' Move to the next record in the Copy table
DatCopy.Recordset.MoveNext
Wend

You don't show it, but somewhere in your code you are deleting a record. When you delete a record the record pointer does not move, it remains pointing at a non-existing record.
Its best to refresh the recordset whenever you delete a record. DataCopy.Refresh will do it.
Be careful with move Movefirst and Movelast. If the record deleted was the first first or last record respectively, they will produce an error.
It may be that there is no way you can prevent the error form occurring. Without seeing all the code it is impossible to tell. If this is the case you may have to implement an error trap using VBs error handling facilities.
Stuart

![]() |
security : OOP vs Proced...
|
C++ 2 dimensional char ar...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |