Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 21: Building Multiuser Applications


787


If ctl.Tag = “Key” Then ‘Ignore key field
‘Do nothing...
Else
frmRS.Fields(ctlName).Value = ctl.Value
End If
Next x
Case “Edit”
frmRS.Index = “PrimaryKey”
frmRS.Seek “=“, lValue
ws.BeginTrans
frmRS.Edit
For x = 0 To frmRS.Fields.Count - 1
ctlName = frmRS(x).Name
Set ctl = frm.Controls(ctlName)
If ctl.Tag = “Key” Then
‘Do nothing...
Else
frmRS.Fields(ctlName).Value = ctl.Value
End If
Next x
Case Else
GoTo ExitHere
End Select
frmRS.Update
ws.CommitTrans
ExitHere:
Exit Function
HandleError:
ws.Rollback
GoTo ExitHere
End Function


Notice that every effort has been made to assure a successful update:

l Locking is set to optimistic locking (LockEdits = False).

l (^) Transactions are used on the current workspace.
l The procedure uses a Select Case statement and the value passed from the Tag prop-
erty to decide what action should be taken.
The update is essentially the reverse of the UpdateDisplay procedure, with a few exceptions:
l (^) An AddNew (or Edit) method is invoked, and again you step through each field in the
recordset’s Fields collection, except this time you update values in the recordset instead of
updating controls on the form.

Free download pdf