954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Filtering data from access database

Hi

I have a problem when filtering this acces database, this is what i have found so far:
1. when i do it with one criteria it works
2. when i concatenate two clauses with direct values it works
3. but when i assign a variable instead of direct values it does not work!!

i do not know what i am doing wrong, i have tried to work around it but i get the same problem. the error that i get is tpe mismatch, but i can't see it.

below is the code (just the portion of it)

thanks in advance

datefilter = txtFilter_Day.Text
namefilter = cmbFilter_name.Text

rstRecordset.Filter = "Date='05/24/05' AND Name='Wiliam'"  'this works
rstRecordset.Filter = ("Date='" & datefilter & "'")                'this works

rstRecordset.Filter = ("Date='" & datefilter & "'") AND ("Name='" & namefilter & "'")  'this does not work

rstRecordset.Filter = "Date='" & datefilter & "'" And "Name='" & namefilter & "'" 'this does not work
williamrojas78
Junior Poster
111 posts since Jun 2005
Reputation Points: 23
Solved Threads: 10
 

Well for one thing, on your very last line, your "and" is being referenced as a visual basic keyword, and NOT a filter query.

rstRecordset.Filter = "Date='" & datefilter & "'" And "Name='" & namefilter & "'"

you never put and back in a string, something like:

rstRecordset.Filter = "Date='" & datefilter & "' And Name='" & namefilter & "'"

might be closer to what you are looking for ;) (the same principle about AND, being outside of the string, applies to the first query that doesn't work also)

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Great, that was the answer,

Thanks again.

williamrojas78
Junior Poster
111 posts since Jun 2005
Reputation Points: 23
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You