OpenReport with filter fails

A

antgel

Hi all,

I'm having a filter problem.

DoCmd.OpenReport "rptPriceListWholesale", acViewPreview, _
"seasonid = 12"

Works, except that the filter is ignored. Filter On is set to Yes in Design
View.

One strange thing is that if I type:
?Report_rptPriceListWholesale.Filter
in the immediate window whilst the report is onscreen, I would expect to see
"seasonid = 12". But I just get a blank line.

Ideas? I have an appaling workaround, which is to send the filter string as
an argument and set it in Report_Open.

A
 
A

Allen Browne

You are missing a comma.
The filter in your example needs to go in the WhereCondition argument:

DoCmd.OpenReport "rptPriceListWholesale", _
acViewPreview, , "seasonid = 12"
 
S

SA

A:

1.) Problem 1 is with your Docmd. statement. You are not applying a filter,
but rather specifying a parameter for a filter query which isn't the same
thing. Your call should be as below, (note the additional comma in line 1:

DoCmd.OpenReport "rptPriceListWholesale", acViewPreview, , _
"[seasonid] = 12"


2.) There's no need to set the filterOn property in design view when calling
a report with a SQL Where filter, Access will apply it automatically.

3.) Note that if [SeasonID] is a string rather than a true number field,
then you've got to concantate the SQL WHERE a bit differently as in

"[SeasonID] = '12'"
 
A

antgel

Allen said:
You are missing a comma.
The filter in your example needs to go in the WhereCondition argument:

DoCmd.OpenReport "rptPriceListWholesale", _
acViewPreview, , "seasonid = 12"

Indeed. Thanks Allen. I'll put it down to waking up at 5am and coding all
day. :)

Antony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top