?
Solved

Applyfilter using string variable

Posted on 2008-06-10
4
Medium Priority
?
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 77

Accepted Solution

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

Assisted Solution

by:koutny
koutny earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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