Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if a record is deleted

Status
Not open for further replies.

tombirch

Programmer
Sep 2, 2000
16
DK
I am getting an error in my code when looping through a recordset , because a record is deleted.

Does anyone know how I can check if a record is deleted?


Tom
 
Tom,

Please elaborate a bit. Is this a multiuser db? What is the Recordset based on? Are you deleting records within the Loop? Could you post some of the code, commenting on where the err occurs?



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Well my code is a bit complicated as the error occurs when I am filling a treeview object.
It is a multiuser database, and I am not deleting records in the code, but I use the recordset of the form where the treeview object is located, and this is where the deletion is taking place.
So far I have solved the problem using errortrapping, with a function where I check for a value in the record. But I am sure there is a better way to check if a record is deleted?
Here is the function:

Private Function isrecorddeleted(xvar As Field) As Boolean
On Error GoTo errorhandling
dummy = xvar.Value 'to trigger error if deleted
isrecorddeleted = False
Exit Function

errorhandling:
If Err.Number = 3167 Then
isrecorddeleted = True
Else
MsgBox "An error occured: error:" & Err.Number
End If
End Function
 
Tom,

Getting the error "record deleted" occurs when/where you create a recordset (dynaset) and delete records which you then 'traverse'. In my experience, I usually would use the source (your treeview) and set it up to only show records which i wanted to operate on. If the operation was to 'delete' the records, I would just collect them in a 'batch' and do a delete query on the whole (enchalida). I would not normally set up a user accessible control to select records for different manipulation, and thus don't see the record deleted err. I do not know any specifics of your app, but I suspect that you are using the treeview to do different operations on records without refreshing the underlying recordset. Thus "deleted" records remain in the recordset and your app traverses the recordset, triggering the error. If this is the situation, I don't know of a soloution other than your error trapping or refreshing the recordset after the operations (especially the delete).



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top