Imagine a table(tblEmployee) set up as follows:
- EmpID(PrimaryKey)
- EmpName(ShortText)
- EmpNo(ShortText)
- EmpPhoto(Attachment)
On a form I want to be able to select Employee's Name from a Combobox(EmpName) so that the other controls update and show me the Number and Photo of the selected employee.
I Have made a form(frmEmployee) and selected the the Record Source as:
SELECT tblEmployee.* FROM tblEmployee;
and added all the fields to the form through "Add existing fields" tab. I then changed the textbox(EmpName) to a combobox with two columns, first of which has a width of zero, and changed the Row Source to :
SELECT tblEmployee.ID, tblEmployee.EmpName
FROM tblEmployee;
So the user can see and choose any employee's name without having to deal with primary keys(EmpID). Also The afterUpdate event of the combobox(EmpName) is like this:
Private Sub EmpName_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![EmpName], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
This gets me the functionality I want but Also Whenever I choose another Employee Name from the combobox the current Employee's Name is Updated to the ID(EmpID) of the newly selected Employee.
How to fix this? Also is there any other faster better way to do this?