using docmd.openreport method

  • Thread starter Thread starter Greg in Detroit
  • Start date Start date
G

Greg in Detroit

I am having trouble with the openreport method, and don't know if I'm trying
to do something that can't be done, or if I have a syntax problem.

The basic question is: should I be able to open a report without a
recordsource property defined, then name the underlying query in visual
basic?

I'm using the code: DoCmd.OpenReport "MyReport", acPreview, "MyQuery"

This returns a report with no records.

If I set the report's Record Source Property to MyQuery, it works fine. But
I want to use the same report with various queries.

Thanks for whatever help is given.

Greg in Detroit
 
Greg said:
I am having trouble with the openreport method, and don't know if I'm trying
to do something that can't be done, or if I have a syntax problem.

The basic question is: should I be able to open a report without a
recordsource property defined, then name the underlying query in visual
basic?

I'm using the code: DoCmd.OpenReport "MyReport", acPreview, "MyQuery"

This returns a report with no records.

If I set the report's Record Source Property to MyQuery, it works fine. But
I want to use the same report with various queries.


Using the OpenReport method's Filter argument will not set
the report's record source.

You can only set a report's RecordSource property in the
report's Open event.

If the only difference in the queries is their Where clause,
then you would be better off using a single query whithout a
where clause and using the OpenReport method's
WhereCondition argument instead.
 
Marshall,
Your suggestion was right-on. Worked perfectly, and Thanks!

But for my own understanding . . . what is the purpose of the FilterName
part of the OpenReport Method? "Help" says the FilterName is a query in the
current database. But if the report's recordsource is a different query
than that used as FilterName, could you give an example of how would
FilterName be used?

Many thanks. Greg
 
Greg said:
Marshall,
Your suggestion was right-on. Worked perfectly, and Thanks!

But for my own understanding . . . what is the purpose of the FilterName
part of the OpenReport Method? "Help" says the FilterName is a query in the
current database. But if the report's recordsource is a different query
than that used as FilterName, could you give an example of how would
FilterName be used?

Actually, I can't come up with an example. I've never found
a use for that feature and I've never even heard of a
problem where using it was the best solution.
--
Marsh
MVP [MS Access]


 
Try this for your code

Docmd.openreport "myreport",acviewpreview,,"[myquery] =" & "'" &
Me![list95].column(0) & "'"

This line i lauched from a form with a list box that the user setup the
query just play with the line and you should get it working

hope this helps
 
Back
Top