Jun 08 2020 09:30 AM
I have a table with 4 fields viz Employee ID (Primary key), FirstName, Surname and Date of Birth. The combination of Firstname, Surname and DOB is UNIQUE.
My objective is to find out the Employee ID. I have designed a form which has 3 DEPENDENT combo boxes for Firstname, Surname and DOB respectively.
I expect that after updating the 3 combo boxes a textbox should autofill to reflect the Employee ID. How should I approach this.
Depicting the above situation in attached excel file for easy understanding.
Sep 21 2020 02:30 AM
Hereby a possible solution. I assume you have some basic SQL and VBA knowledge.
First, set the row sources for the combo boxes with a SQL statement like:
Then, define an After Update event for the DOB combo box (that looks up/sets the Employee ID):
Finally, enter this VBA code into the AfterUpdate event:
Private Sub cmbDOB_AfterUpdate()
'Lookup the Employee ID
Me.txtEmployee.Value = DLookup("EmployeeID", "Employee", "Firstname='" & Me.cmbFirst & _
"' AND Surname='" & Me.cmbSur & _
"' AND DOB=#" & Format(Me.cmbDOB, "yyyy-mm-dd") & "#")
End Sub
When you open the form in view mode, after selecting the combo boxes, the Employee ID is determined:
Hope this helps you in the right direction.
Best wishes,
Tieme