We have a routine that is used by multiple users at once, so needs to rely on record locking. The procedure is designed to read the first record in a file that has no entry in a specific field and then to stamp the users name in this field (thus reserving the record for them). Because more than one user can be executing this routine at once, it is important that two people could not be writing their name against the same blank field at the same time.
The code looks like this:
Dim db As Database, rs As Recordset, ok2go as integer
ok2go=false
Set db = CurrentDb()
Set rs = db.OpenRecordset(“SELECT * FROM [MasterFile] where isnull([Processedby])=true and isnull([processedon])=true and [followupon] <= now() ORDER BY [MasterFile].UniqueRef", dbOpenDynaset, dbSeeChanges)
If rs.EOF = False Then
rs.MoveFirst
Do While ok2go = False
If IsNull(rs![ProcessedBy]) = True Or rs![ProcessedBy] = CurrentUser() Then
rs.Edit
rs![ProcessedBy] = [Forms]![splash]![TheUser]
rs.Update
If rs![ProcessedBy] = [Forms]![splash]![TheUser] Then
ok2go = True
End If
Else
rs.MoveNext
End If
Loop
End If
Having read articles in the lounge on locking in SQL and using .lockedits =true, I can get the code to report 3197 "The Microsoft Jet Database Engine stopped the process because you and another user are attempting to change the same data at the same time", which is part of the way there (at least two users don't end up with the same record), but does anyone know of a way to check if the record is locked and if it is move to the next record in the set rather than just wave a flag of defeat?
Perhaps there is a better way that I am trying to use to get the same end result?
Any assistance gratefully received!