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!

Vba filter not working 3

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
586
GB
Please could someone correct my filter code. Thank you, its driving me mad!! Mark

Code:
Me.Form.Filter = "Hol_Staff_Member ='" & Me.cbo_Staff_Initials_Sort & "'" And "[Hol_Year]='" & Me.cbo_Holiday_Year & "'"
 
I would try this assuming both fields are text.

Code:
Me.Form.Filter = "Hol_Staff_Member ='" & Me.cbo_Staff_Initials_Sort & "' And [Hol_Year]='" & Me.cbo_Holiday_Year & "'"

Make sure you set the filter on.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Moss100 said:
its driving me mad!!

Help yourself by:

Code:
Dim strFilter As String
...
strFilter = "Hol_Staff_Member = '" & Me.cbo_Staff_Initials_Sort & "' And Hol_Year = '" & Me.cbo_Holiday_Year & "'" 
[blue]Debug.Print strFilter[/blue]
Me.Form.Filter = strFilter

And SEE what your Filter is :)

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Using Andy’s suggestion, you can copy and paste the expression into a SQL view of a query:

SQL:
SELECT * FROM [Your Table] WHERE [paste expression here to check]

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
So... what was the issue? [upsidedown]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Hi Mark,

Based on the snippet you provided, it appears you are trying to filter a form based on two criteria: the staff member initials and the holiday year.

Regarding your question about correcting the code, it looks like the code is missing a closing parenthesis after the first criteria. Here is the corrected code with the parenthesis added:

Me.Form.Filter = "Hol_Staff_Member ='" & Me.cbo_Staff_Initials_Sort & "' And [Hol_Year]='" & Me.cbo_Holiday_Year & "'"

Also, if you're still having trouble getting the desired results, you may want to check if the values of the cbo_Staff_Initials_Sort and cbo_Holiday_Year controls are being properly passed to the filter string.



I hope this helps, and good luck with your project!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top