Need a button to apply a filter (1 Viewer)

chaostheory

Registered User.
Local time
Today, 07:02
Joined
Sep 30, 2008
Messages
69
I have a form created. It displays all the records in the table.

In the Form header i put a text box (txtSearch) with a button(btnFilter) next to it.

People can type in the text box, then click the button to apply the filter

Thats what i want to happen.

Here is the button click code. Needless to say it don't work, and its giving me a popup box asking me for the criteria instead of using the txtSearch text box i have next to it. [Skid] is the name of the field i want the filter based on.

So you type 012345 in the text box i want every record with that in the Skid field to show up.

Help is appreciated, thanks in advance!

Code:
Private Sub btnFilter_Click()
 
    If Len(txtSearch) = 0 Or IsNull(txtSearch) = True Then
        MsgBox "You must enter a Skid ID to search."
 
    Else
        'Filter frmCharacterization based on search criteria
        Me.Filter = "[Skid] LIKE " & txtSearch.Value
        Me.FilterOn = True
 
 
        'Close frmCharacterization
 
        MsgBox "Results have been filtered."
 
    End If
 
End Sub
 
Last edited:

Rabbie

Super Moderator
Local time
Today, 15:02
Joined
Jul 10, 2007
Messages
5,906
try
Code:
Private Sub btnFilter_Click()
 
    If Len(txtSearch) = 0 Or IsNull(txtSearch) = True Then
        MsgBox "You must enter a Skid ID to search."
 
    Else
        'Filter frmCharacterization based on search criteria
        Me.Filter = "[Skid] LIKE *" & me!txtSearch & "*"
        Me.FilterOn = True
 
 
        'Close frmCharacterization
 
        MsgBox "Results have been filtered."
 
    End If
 
End Sub
 

chaostheory

Registered User.
Local time
Today, 07:02
Joined
Sep 30, 2008
Messages
69
changed the line to

Code:
Me.Filter = "[Skid] LIKE *" & me!txtSearch & "*"

Clicking the button doesnt do anything.
 

chaostheory

Registered User.
Local time
Today, 07:02
Joined
Sep 30, 2008
Messages
69
Got it!

Not sure why but i found an exmaple online and modeled my filter line after it and it works great.

Why do i need 3 quotes before and after the line?

Code:
Me.Filter = "skid = """ & Me.txtSearch & """
 
Last edited:

Users who are viewing this thread

Top Bottom