Chapter 21: Building Multiuser Applications
785
Dim lngReturn As Long
On Error GoTo MoveNext_Err
‘Move to the next employee record:
frmRS.INDEX = “PrimaryKey”
‘Note: The Seek method works only on local tables:
frmRS.Seek “=“, lValue ‘Search for displayed employee
If Not frmRS.NoMatch Then
‘ Move to the next employee record
frmRS.MoveNext
For x = 0 To frmRS.Fields.Count - 1
ctlName = frmRS.Fields(x).Name
frm.Controls(ctlName).Value = _
frmRS.Fields(x).Value
Next x
End If
MoveNext_End:
Exit Function
MoveNext_Err:
‘Call ErrorRoutine, specifing zero retries:
lngReturn = ErrorRoutine(0)
GoTo MoveNext_End
End Function
Using a combo box
The second method for changing position within the form’s recordset is with a combo box. cbo-
Employee uses the employee’s ID number, which is the bound column of the combo box. It’s
passed to the UnboundSearch function (shown here) as the variable lValue, which is called
when the AfterUpdate event is triggered. UnboundSearch sets the recordset’s index property
to EmployeeID and then uses the Seek method to locate the employee chosen. If a match is
found after using the Seek method, the now familiar looping routine is used to extract field values
from the recordset and fill in the corresponding controls on the Employees form. The code is
shown here:
Function UnboundSearch( _
frm As Form, _
frmRS As DAO.Recordset, _
lValue As Long) As Integer
Dim ctlName As String
Dim x As Integer
frmRS.Index = “PrimaryKey”
‘Note: The Seek method works only on local tables:
frmRS.Seek “=“, lValue
If Not frmRS.NoMatch Then
For x = 0 To frmRS.Fields.Count - 1
ctlName = frmRS.Fields(x).Name
frm.Controls(ctlName).Value = _
frmRS.Fields(x).Value
Next x
End If
End Function