OpenReport with filter fails

  • Thread starter Thread starter antgel
  • Start date Start date
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
 
You are missing a comma.
The filter in your example needs to go in the WhereCondition argument:

DoCmd.OpenReport "rptPriceListWholesale", _
acViewPreview, , "seasonid = 12"
 
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'"
 
Back
Top