Open report

eacollie

Registered User.
Local time
Today, 06:02
Joined
May 14, 2011
Messages
159
I'm trying to add onto the open report command but having problems.

I'm using the filter on a form to populate labels
Code:
DoCmd.OpenReport "Labels_Contacts", acViewPreview, , Me.Filter & "and [Mail] = 'Yes'"
and Access doesn't like this.
I'm getting a 3075 error "Syntax error (missing operator) in query expression 'and [Mail] = Yes'.
What is the correct syntax for this?

Thanks much
 
Given the error message, it doesn't look like there's a filter. You may want to test for that and adjust (Len function). Also, if Mail is a yes/no field, you wouldn't want the single quotes around it.
 
There is a filter because it opens the report will the filtered list. I'm trying to add something to the filter when I open the report and I think that's what's causing the problem. :banghead:
 
What you've done looks fundamentally correct, though I'd add a space in front of "and", plus the data type comment above. The error implies there's no existing filter though. Can you post the db here?
 
I can't get the file down to the 2 mb limit for attaching.
 
Did you compact/repair and then zip?
 
You can email it to

pbaldy
gmail
com

but I probably won't get to it until tomorrow.
 
In response to your email:

I placed the following in the code for the click event of the mailing labels control:

Dim currentfilter
currentfilter = (IIf(Me.Filter = "", " [Mail] = Yes", " ([Mail] = Yes) and " & "( " & Me.Filter & ")"))
DoCmd.OpenReport "Labels_Contacts", acViewPreview, , currentfilter

The only other issue I have is clearing of the filters.
The template is written with macros, so I’m not sure of the syntax.
The only way I can clear the filter is by using the ribbon. Any idea what code this “clear all filters” uses and how to put that into the macro behind the “show all records” control?

The VBA method to clear the filters would be:

Me.FilterOn = False

or for a different form:

Forms!FormName.FilterOn = False

The macro uses SetValue to do the same thing.
 

Users who are viewing this thread

Back
Top Bottom