G
george 16-17
Greetings all,
I have a three column list box (lstEmpNames) that contains a employee's last
name, first name, and EmpID. I use this list box to find records on my main
form. The bound column is (2) - EmpID.
Here is the code, based on Allen Browne's http://allenbrowne.com/ser-03.html:
'start code************************************
Private Sub lstEmpNames_AfterUpdate()
'Finds record on main form when list box name is clicked
Dim rs As DAO.Recordset
If Not IsNull(Me.lstEmpNames) Then
If Me.Dirty Then
Me.Dirty = False
End If
Set rs = Me.RecordsetClone
rs.FindFirst "[EmpID] = " & Me.lstEmpNames.Column(2)
If rs.NoMatch Then
MsgBox "No matching records", vbOKOnly, "Try again"
Else
'Display the found record in the form.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If
End Sub
'end code***********************
The code works great, but when I use the form's navigation buttons, the
listbox loses focus and does not highlight the current record. Is there
method to synchronize the list box when the navigation buttons are used? I
searched the discussion groups without finding a solution.
Thanks in advance and any direction is appreciated,
george
I have a three column list box (lstEmpNames) that contains a employee's last
name, first name, and EmpID. I use this list box to find records on my main
form. The bound column is (2) - EmpID.
Here is the code, based on Allen Browne's http://allenbrowne.com/ser-03.html:
'start code************************************
Private Sub lstEmpNames_AfterUpdate()
'Finds record on main form when list box name is clicked
Dim rs As DAO.Recordset
If Not IsNull(Me.lstEmpNames) Then
If Me.Dirty Then
Me.Dirty = False
End If
Set rs = Me.RecordsetClone
rs.FindFirst "[EmpID] = " & Me.lstEmpNames.Column(2)
If rs.NoMatch Then
MsgBox "No matching records", vbOKOnly, "Try again"
Else
'Display the found record in the form.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If
End Sub
'end code***********************
The code works great, but when I use the form's navigation buttons, the
listbox loses focus and does not highlight the current record. Is there
method to synchronize the list box when the navigation buttons are used? I
searched the discussion groups without finding a solution.
Thanks in advance and any direction is appreciated,
george