Contact us
LISTING 3.  Two Procedures to Find Employees Based on IDs

Sub locateEmployee()

'Ask for employee ID and pass it on to findByID
    employeeNumber = InputBox("Type the ID for the employee you want", _
    "Programming Microsoft Access 2000")
    findById CLng(employeeNumber)
End Sub

Sub findById(eid As Long)
On Error GoTo findByIdTrap

'Set focus to employee ID field and launch find
    Forms("frmemployees").EmployeeID.SetFocus
    DoCmd.FindRecord eid

findByIdExit:
'Report mismatch before exiting
    If Forms("frmemployees").EmployeeID <> eid Then
    MsgBox "No employee with ID " & eid & ".", _
        vbExclamation, "Programming Microsoft Access 2000"
    End If
    Exit Sub
    
findByIdTrap:
    If Err.Number = 2450 Then
'Open form if it is closed and start find again
    openForm
    Resume
    Else
    Debug.Print Err.Number, Err.Description
    End If

End Sub