OpenReport Where statement not working

  • Thread starter Thread starter neonx3
  • Start date Start date
N

neonx3

Hi,

I'm using Access 2000.

I want to open a report from a filtered form, which has the query
"Loadlist Query1" as its source (or whatever you call it). I think the
easiest way to do this is:

DoCmd.OpenReport stdocname, acViewPreview, "Loadlist Query1",
Me.Filter

but unless I specify the sorting order on the report, this doesn't
populate the report at all. Changing the statement to this:

DoCmd.OpenReport stdocname, acViewPreview, "Loadlist Query1" &
Me.Filter, Me.Filter

gives the correct, filtered records in the report, but they still are
not sorted. This makes sense, because I haven't specified a sort order
anywhere.

When I specify a sort order, then the first DoCmd statement works,
except that the Me.Filter statement (that is, the WHERE statement)
seems to be ignored. The second DoCmd statement gives the same thing
as the first.

Any idea what I'm doing wrong?

Thanks,
Danny Fingas
 
Danny, I don't think the FilterName argument of OpenReport is worth the
effort to even try it. Use the WhereCondition argument instead.

If you are trying to filter the report the same way as the form is filtered,
try this:
Dim strWhere As String
If Me.FilterOn Then
strWhere = Me.Filter
End If
DoCmd.OpenReport stDocName, acViewPreview, , strWhere
 
Hi Allen,

I tried what you said, but it still seems to ignore the WhereCondition
argument. I double-checked that Me.Filter is not empty.

thank you very much,
Danny
 
The Filter must operate on fields that exist in the report's recordsource.
If is is not working, compare the two.
 
Thank you very much for your help. Your first suggestion seems to be
working now, although I don't think I changed anything else since
trying it before. Maybe closing & re-opening Access did something.
 
Back
Top