Each employee has a unique identification number called "BANNER_ID" .
Each employee's last name and first name are in the database but are not unique (obviously).
The data is stored in a table named EMPLOYEE.
I want to create a search option whereby managers can search for an employee by "BANNER_ID"
by entering the number and pressing a command button named "Search".
I want to create an accompanying search option whereby managers can search for an employee
by selecting his or her last name from a combo box (LAST_NAME) and then first name from
another combo box (FIRST_NAME).
When a last name is selected, I would like the combo box of first names to narrow to only
first names that are associated with the selected last name.
I want both search options to be available.
I have been helped with the following code that searches for employees based on their
last name. However, I am having trouble adapting it to work with my new needs listed above.
Expand|Select|Wrap|Line Numbers
- Private Sub cmdSearch01_Click()
- Dim strStudentRef As String
- Dim strSearch As String
- 'Check txtSearch01 for Null value or Nill Entry first.
- If IsNull(Me![txtSearch01]) Or (Me![txtSearch01]) = "" Then
- MsgBox "Please enter a last name!", vbOKOnly, "Martin DH Message"
- Me![txtSearch01].SetFocus
- Exit Sub
- End If
- '---------------------------------------------------------------
- 'Performs the search using value entered into txtSearch01
- 'and evaluates this against values in LAST_NAME
- DoCmd.ShowAllRecords
- DoCmd.GoToControl ("LAST_NAME")
- DoCmd.FindRecord Me!txtSearch01
- LAST_NAME.SetFocus
- strStudentRef = LAST_NAME.Text
- txtSearch01.SetFocus
- strSearch = txtSearch01.Text
- 'If matching record found sets focus in LAST_NAME and shows msgbox
- 'and clears search control
- If strStudentRef = strSearch Then
- MsgBox "Match Found For: " & strSearch, , "Martin DH Message"
- LAST_NAME.SetFocus
- txtSearch01 = ""
- 'If value not found sets focus back to txtSearch01 and shows msgbox
- Else
- MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
- , "Martin DH Message"
- txtSearch01.SetFocus
- End If
- End Sub
Martin DH