Filter in report

H

Hans

How to use a query object as filter in a report?
Example:
Filtername = ... "queryname"
DoCmd.OpenReport "reportname", acViewPreview, , "filtername"

How to use Reports("name").RecordSource=sqlString

Thanks, Hans
 
A

Allen Browne

While I'm not completely clear about what you want, you can do something
very much like your last line if you use the Open event procedure of the
report.

Example:

Private Sub Report_Open(Cancel As Integer)
Dim strSql As String
strSql = "SELECT * FROM Table1 WHERE (Inactive = False);"
Me.RecordSource = strSql
End Sub
 
H

Hans

Thanks for the quick reaction.

What I want is with "queryname" pointing to one of the (allready made)
queries in my database, like:

DoCmd.OpenReport "reportname", acViewPreview, , "queryname"

But this way doesn't work.

Thanks, Hans
 
A

Allen Browne

You can assign the saved query as the RecordSource of the report in
Report_Open, e.g.:
Me.RecordSource = "queryname"

OpenReport offers 2 ways to filter the report: a FilterName, and a
WhereCondition. The WhereCondition works reliably; the FilterName doesn't
IME.
 

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