Solved

Applyfilter using string variable

Posted on 2008-06-10
4
278 Views
Last Modified: 2013-11-27
I am getting a syntax error on this, and similar versions, please advise.  Thank you.

dim strVal as string
strVal = "Joe Smith"
docmd.applyfilter("filterName"), "fieldName1=" & strVal
0
Comment
Question by:ellenjbr
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 21749120
"fieldName1='" & strVal & "'"
0
 
LVL 12

Assisted Solution

by:koutny
koutny earned 250 total points
ID: 21749383
The syntax error would be caused by wrong calling convention for the ApplyFilter method (brackets).

The line should look like this:

docmd.applyfilter "filterName", "fieldName1='" & strVal & "'"

Also, you do realize that passing the second condition is going to be applied to the saved filter, further filtering the records.
If you don't want that you can just set the Filter property for the form:

me.filter = "fieldName1='" & strVal & "'"
me.filteron = true


0
 

Author Comment

by:ellenjbr
ID: 21751458
I will try your suggestions and get back with you this evening ... thank you!
0
 

Author Closing Comment

by:ellenjbr
ID: 31465639
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now