• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 18. Developing for a Multiuser E... > Practical Examples: Making an Applic...

Practical Examples: Making an Application Multiuser Ready

The Time and Billing application is built mostly around forms. Because it's unlikely that two users will update the data in the same record at the same time, you can opt for optimistic locking. This reduces the chance of a page of records inadvertently being locked for a long period of time. The following example illustrates how you can use the form's Error event to override the default locking error messages:

Listing 18.7. Overriding default error handling under a form.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
   On Error GoTo Form_Error_Err:
   Dim intAnswer As Integer
   If DataErr = 7787 Then  'Data Has Changed Error
      intAnswer = MsgBox("Another User Has Modified This Record " & vbCrLf & _
         "Since You Began Editing It. " & vbCrLf & vbCrLf & _
         "Do You Want To Overwrite Their Changes? " & vbCrLf & _
         "Select YES to Overwrite, NO to Cancel Your Changes", _
         vbYesNo, "Locking Conflict")
   End If
   If intAnswer = vbYes Then
      Dim db As DATABASE
      Dim rst As Recordset
      Dim strSQL As String
      Dim fld As Field

      strSQL = "Select * from tblClients Where ClientID = " & Me!ClientID
      Set db = CurrentDb
      Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
      For Each fld In rst.Fields
         If Nz(fld) <> Nz(Me(fld.Name)) Then
            fld.Value = Me(fld.Name).Value
         End If
      Next fld
   End If
   Response = acDataErrContinue
   Exit Sub

      MsgBox "Error # " & Err.Number & ": " & Err.Description
      Exit Sub
End Sub




Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint