Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 21: Building Multiuser Applications


777


Dim sSQL As String
Dim lngReturn As Long
On Error GoTo HandleError
Set db = CurrentDb
sSQL = “Select * from Employees where “ _
& “Employees![EmployeeID] = “ & ID & “;”
Set rs = db.OpenRecordset(sSQL)
‘ Set record locking to Pessimistic Locking
rs.LockEdits = False
rs.Edit ‘ Try to lock the record for editing
rs!LastName = “Smith”
rs.Update
ExitHere:
‘ Exit The Procedure
rs.Close
Exit Sub
HandleError:
‘Notice that we’re passing zero to ErrorRoutine.
‘This means not to attempt any retries:
lngReturn = ErrorRoutine(0)
Select Case lngReturn
Case 3
rs.Update
MsgBox “Record Was Updated!”
Case 4
MsgBox “Edit Was Canceled!”
End Select
Resume ExitHere
End Sub


The portion of ErrorRoutine() for handling this error is shown here. Notice how the user is
prompted for the action to be taken. The messaging in this routine is easier to understand than
what you see in Figure 21.9, and the user’s wishes are carried out in a more sophisticated manner
than the default Access actions. Notice also that the option to copy the data to the Clipboard isn’t
provided because this routine assumes that the user wants to either save the record or abandon
changes.

Case 3197
‘ Offer the user a chance to cancel
‘ the edit or save the changes
strMessage = “The record you are trying “ _
& “to save has been changed “ _
& “since your edit began” & vbCrLf & vbCrLf _
& “Do you want to save it anyway?”
lngReturn = MsgBox(strMessage, vbYesNo)
Select Case lngReturn
Case vbYes
Free download pdf