Hello,
I want to add a button to a form to open a one of the reports in excel.
I am using Access 2003 and I am still a beginner in VBA, so could someone help me in writing the code of this button.
thanks in advance
Regards
Hello,
I want to add a button to a form to open a one of the reports in excel.
I am using Access 2003 and I am still a beginner in VBA, so could someone help me in writing the code of this button.
thanks in advance
Regards
Here's the full code from behind a button called cmdPreviewReport that opens a report called "rpt_MyReport".
Code:Private Sub cmdPreviewReport_Click() On Error GoTo Err_cmdPreviewReport_Click Dim stDocName As String stDocName = "rpt_MyReport" DoCmd.OpenReport stDocName, acPreview Exit_cmdPreviewReport_Click: Exit Sub Err_cmdPreviewReport_Click: MsgBox Err.Description Resume Exit_cmdPreviewReport_Click End Sub
The simplest possible command for this would be to hard-code the report name in the DoCmd like this
Here's a page where you can read up and learn other parameters if you don't want to open in preview mode.Code:DoCmd.OpenReport "rpt_MyReport", acPreview
http://www.blueclaw-db.com/docmd_openreport.htm
hello
thanks a lot for your help,actually I used the code you gave me to open a report and it works now, but I wonder if there is a way to open the report as MS EXCEL file directly
regards
You can export report to Excel. Be aware, reports don't always export nicely. Better to export table or query. Look at DoCmd.TransferSpreadsheet method. Or open report in PrintPreview and right click > Export > Excel.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
thanks a lot this is what I need ^_^