Solved

Applyfilter using string variable

Posted on 2008-06-10
4
283 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 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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 …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

726 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