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!

Export a subsection of a reports records 1

Status
Not open for further replies.

Fubear

IS-IT--Management
Sep 11, 2002
299
GB
I am trying to write a bit of code to output a range of records within a report to an excel format.

I have the code so that when u click a button, it will ask you where to save the file, but when you save it saves the whole report (130 pages).

The form has several controls to create a filter that will return the correct number of results, but I dont know how to apply it to the command to export as an excel sheet.

Currently the command is:
DoCmd.OutputTo acOutputReport, "PrintData"

I have a string called finalString that contains the correct filter. Is there any way to apply this filter to the report "PrintData" before exporting it to excel?
 
What you might want to try is outputting the Report to a Table and then Export that to Excel.
You would have to create a Temporary Table to hold the values from the report.
In the report Open Event you would run a Delete Query to empty the Temp Table.
In the Format Event for the Detail Section, you would use an Insert Into statement to get the values from the report to the Temp Table
Dim strSQL as String
strSQL = "Insert Into TempTable ("Field1","Field2",..."Fieldn") Values ('" & ReportField1 & '", '" & ReportField2 & '", '" & ReportFieldn & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True


This will insert current record values in your Temp Table based on the Filters in your Form.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top