Filter mainform using listbox

Del_Piero_3

Registered User.
Local time
Today, 20:55
Joined
Jul 20, 2004
Messages
33
I have a form called “frm_TrainingLog” based on “TrainingLog” table. This form is continuous and tabular – I need to have it this way. In the header of this form I’ve created a listbox called “QuickSearch” which displays staff details i.e. StaffID, Name etc.

The mainform and the listbox are linked using the following code:

Code:
Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[StaffID] = " & Str(Me![QuickSearch])
    Me.Bookmark = rs.Bookmark

The above code does partially work and selects the right record in the mainform but it doesn’t filter out rest of the records which are not equivalent to selected StaffID from the listbox.

I could really do with someone’s help….thanks
 

Attachments

  • frm_TrainingLog.jpg
    frm_TrainingLog.jpg
    83.4 KB · Views: 157
Last edited:
Solution

Never mind, solved it.....heres the solution, might help someone else:

Code:
Private Sub QuickSearch_Click()
On Error Resume Next
     
    QuickSearch.SetFocus
    If QuickSearch.Value > 0 Then
        Me.Filter = "[StaffID]=" & QuickSearch.Value
        Me.FilterOn = True
    End If
End Sub
 
For the record, it is only necessary for the control to have the focus if you are using the .Text property. If you use the .Value property, which is the default property and need not be specified, then you don't have to give the focus to the control first.
 

Users who are viewing this thread

Back
Top Bottom