Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ouput report to excel file

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi

Is it possible to first apply the filter to the report and then output the report to the excel file?


With this code I just open the report applying the criteria:
DoCmd.OpenReport "WbtReport", acViewPreview, , "[AssetStatus]='active'"

Can I actually send that filtered report to excel not even opening the report?

Thanks
 
You'd need to kinda alter the way you run this, but one of the ways I can output to Excel, or Open the report, is to use the same the same query for a report, and simply change the .SQL property of the query. Here's how (to start off with!) - this code assumes that you are taking the criteria from a combo box (for example you might have a combo box for
AssetStatus that has two values - Inactive, or Active...
Code:
Function fncChangeQuery()
Dim qdfTemp as querydef
Dim strSQL as string

strSQL = "SELECT a,b,c FROM tbl WHERE AssetStatus = '" & me.cboAssetStatus.Value & "'" 

Set qdfTemp = CurrentDb.QueryDefs("qryWbtReport")
What I've done there is to open up the queries collection, specifically the query that runs the report

Code:
qdfTemp.SQL = strSQL
Set qdfTemp = Nothing

I then assign strSQL to the SQL property of the Query. Finally set qdfTemp to nothing so I don't have open objects.

Code:
End Function

From here you can call a function to either output the report to Excel (DoCmd.OutputTo), or run the report, depending on what the user has requested!

HTH

Mincefish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top