Code for Filtering Records

D

De'Ville

I am quite new to this, I have this button in my form, it
filters the records in a table using the following piece
of code bellow. What i am doing is filtering the records
using a field in that my table called 'Status', in the
field status some of the records have the word 'Active'
and others have the word 'Resolved' when I click the
button to filter the records so that only records with
the word 'Active' in the 'Status' field are displayed, it
brings up a little dialoge box that says "Enter Parameter
Value" if I Type 'Active' The correct records are
displayed, which is ok, but what i am really trying to do
is make the button so that it automatically looks for the
correct records without my having to type the
word 'Active'. thanks

Private Sub FilterButton_Click()
On Error GoTo Err_FilterButton_Click


Dim QryFld As String
Dim CurRecNo As String


Let CurRecNo = Form.CurrentRecord
QryFld = " Status "

DoCmd.ApplyFilter , "[Status] like Active"


Exit_FilterButton_Click:
Exit Sub

Err_FilterButton_Click:
MsgBox Err.Description
Resume Exit_FilterButton_Click

End Sub
 
J

John Vinson

DoCmd.ApplyFilter , "[Status] like Active"

Since Status is a Text field, you must wrap the criterion in quotes.
Also, the LIKE operator is not needed here; it's equivalent to the =
operator if you aren't using any wildcards.

Change this line to

DoCmd.ApplyFilter, "[Status] = 'Active'"

or, perhaps better,

Me.Filter = "[Status] = 'Active'"
Me.FilterOn = True
 
D

De'Ville

Thank You Mr John Vinson
I made the change and it worked perfectly
-----Original Message-----
DoCmd.ApplyFilter , "[Status] like Active"

Since Status is a Text field, you must wrap the criterion in quotes.
Also, the LIKE operator is not needed here; it's equivalent to the =
operator if you aren't using any wildcards.

Change this line to

DoCmd.ApplyFilter, "[Status] = 'Active'"

or, perhaps better,

Me.Filter = "[Status] = 'Active'"
Me.FilterOn = True



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top