Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form - Filter 1

Status
Not open for further replies.

Adams

Technical User
Mar 10, 2001
44
US
I have created a form and would like to filter some data. I have use the Toolbox to create a Command Button Apply Form Filter. How do I link the button to the field I would like to filter?
 
in the onClick event of the button use the following code

me.filter="YourFilterField=" & YourFilterValue
me.filterOn = True

replace YourFilterField and YourFilterValue with the appropriate field name and value
 
Thought I might add for your reference:

The code in my first post is if your filter is numeric
if your filter is a string use the following:

me.filter="YourFilterField='" & YourFilterValue & "'"
me.filterOn = True

The single quotes designate the string value

if your filter is a date, use:

me.filter="YourFilterField=#" & YourFilterValue & "#"
me.filterOn = True

The hash marks designate the value as a date in access
 
Hi Greely
Have a hard time trying to get a filter to work.

I tried to filter my form on the string mba, but it says 'variabel not defined'.

Code:
Private Sub Form_Load()
    Me.Filter = "StudieRichting='" & mba & "'"
    Me.FilterOn = True
End Sub

Pampers.

You're never too young to learn
 
You have to declare your mba variable
Try:

Private Sub Form_Load()
dim mba
Me.Filter = "StudieRichting='" & mba & "'"
Me.FilterOn = True
End Sub
 
Looking at it again, you may not have intended mba to be a variable but the actual string, in which case:

Private Sub Form_Load()
Me.Filter = "StudieRichting='" & "mba" & "'"
Me.FilterOn = True
End Sub

You might want to search this site or others for a tutorial on string handling (concatenation). You'll use it a lot.

Good Luck
 
tnx a lot greely,
you intended right, i meant it as a string, so this was the correct code:
Code:
Me.Filter = "StudieRichting='" & "mba" & "'"
It is so confusing with alle the ""'"'!!!!!!!!!
I used you other line of code also for a filter in a combo
looks like:
Code:
Private Sub cboStudieRichting_AfterUpdate()
    Me.Filter = "StudieRichting='" & cboStudieRichting & "'"
    Me.FilterOn = True
End Sub


Pampers.

You're never too young to learn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top