Filter a report in DoCmd.OutputTo

Warren

Registered User.
Local time
Today, 07:14
Joined
Apr 1, 2009
Messages
13
How do you filter a report you use in

DoCmd.OutputTo acOutputReport, "reportName", ...

I can filter a report in DoCmd.OpenReport

DoCmd.OpenReport "reportName", acViewNormal, , "[fieldname]=" & "whatever"

The DoCmd.OutputTo doc says that if you leave the Objectname parameter blank it will use the active object. Is there a way to make the report I want to use the active object, filter it then call DoCmd.OutputTo ?

Thanks,

Warren
 
As the report based on an underlying query or table you need to apply the filter on that. This inturn will filter the report when generated or outputted.

David
 
The report is based on a query and the filter is dynamic. With:

DoCmd.OpenReport "reportName", acViewNormal, , "[fieldname]=" & whateverString

I change the "whateverString" arg every time it is run.

I did get it to work by calling DoCmd.OpenReport with acViewPreview and then calling DoCmd.OutputTo with the Objectname blank. This seems hacky and is twice as slow if I were to call DoCmd.OutputTo by itself with an objectname, but that does not give me the filter I want.

I assume the above causes the report I need to become active and then DoCmd.OutputTo uses it since its Objectname arg is blank. I think the problem with it being slow is that it opens the report gui for preview and I do not need that.

Is there a way of getting a hold of the report object, filtering it and then making it active without getting any kind of gui involved. I think that would do it.

Thanks

Warren
 
One more item is that all of this is being done in a Function that is being called from a macro which is being started via the command line. There is no form or report event that is involved.
 
Did you manage to solve this?
I have the same problem!
 
Create a query for the basis of the report and change the query before opening the report. You cannot edit the recordsource property of the report unless you are in design mode.

Here's an example:
Code:
Function IT_Request_Report(strID As String)
Dim DB As DAO.Database
Dim QDF As DAO.QueryDef
Dim strSQL As String
    Set DB = CurrentDb
    strSQL = "SELECT IT_REQUESTS.ID, IT_REQUESTS.Sequence, IT_REQUESTS.EYear, IT_REQUESTS.Requestor_Name, IT_REQUESTS.Date_Entered, IT_REQUESTS.Department, IT_REQUESTS.Phone, IT_REQUESTS.email, IT_REQUESTS.Location, IT_REQUESTS.Computer, IT_REQUESTS.Issue_Type, IT_REQUESTS.Issue_Other, IT_REQUESTS.Printer, IT_REQUESTS.CpxMod, IT_REQUESTS.Urgent, IT_REQUESTS.Issue, IT_REQUESTS.Completed_By, IT_REQUESTS.Resolution, IT_REQUESTS.Time_Started, IT_REQUESTS.Time_Ended, IT_REQUESTS.Total_Time, IT_REQUESTS.Status, IT_REQUESTS.Attachments" _
        & " FROM IT_REQUESTS" _
        & " WHERE (((IT_REQUESTS.ID)='" & strID & " '));"
 
    DB.QueryDefs.Delete "IT_RPTBASE_IT_REQUEST"
 
    Set QDF = DB.CreateQueryDef("IT_RPTBASE_IT_REQUEST", strSQL)
 
    Set QDF = Nothing
    Set DB = Nothing
 
 
End Function
 

Users who are viewing this thread

Back
Top Bottom