Export a report to Excel

A

Ana

Hi,

I'd like to export a report to Excel via a cmd. The report is linked to a
stored procedure with a variable bonded to a form's combox.

I guess I'd use a cmd button as below but I don't know the rt syntax. Any
help is appreciated.

Ana

Private Sub CmdExcel_Click()

On Error GoTo Err_CmdExcel_Click

Dim query As String
Dim file As String

query = StoredProcedureFile @Client = Forms![frmParent]![ComboBox]
file = 'c:\..\Desktop\test.xls'

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, query,
file, false

Exit_ CmdExcel _Click:
Exit Sub
Err_ CmdExcel _Click:
MsgBox Err.Description
Resume Exit_ CmdExcel _Click
End Sub
 
D

Dorothy

Hi,

I'd like to export a report to Excel via a cmd. The report is linked to a
stored procedure with a variable bonded to a form's combox.

I guess I'd use a cmd button as below but I don't know the rt syntax. Any
help is appreciated.

Ana

Private Sub CmdExcel_Click()

On Error GoTo Err_CmdExcel_Click

Dim query As String
Dim file As String

query = StoredProcedureFile @Client = Forms![frmParent]![ComboBox]
file = 'c:\..\Desktop\test.xls'

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, query,
file, false

Exit_ CmdExcel _Click:
Exit Sub
Err_ CmdExcel _Click:
MsgBox Err.Description
Resume Exit_ CmdExcel _Click
End Sub

Hi there. I believe instead of TransferSpreadsheet you need something
like this.

Dim stDocName As String

stDocName = "Report"
DoCmd.OutputTo acReport, stDocName, acFormatXLS, "Report.xls"

Good luck.

Dorothy
 

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