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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

report to excel

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

Dim stDocName As String

stDocName = "Query3"
DoCmd.OutputTo acReport, stDocName

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub

The above code sends a report relating to Query 3 to excel
but if I modify the code (see below) to try to send the report to a specific file, it sends a report relating to all the data in table not just the query ?



Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

DoCmd.OutputTo acReport, _
"sheet1", acFormatXLS, "E:\test.xls", 0

Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub

can anyone tell me where I am oing wrong,
excuse my ignorance but I am a beginner
 
The problem is not that you're sending the data to a specific file, rather it's with the name of the Access object you're trying to export. Right now the code will export an object in your database called "sheet1", which probably contains all your data. Create a query that contains the data you want and reference it in your code instead of "sheet1".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top