Results 1 to 5 of 5
  1. #1
    momani is offline Novice
    Windows XP Access 2003
    Join Date
    May 2013
    Posts
    10

    Opening a report in excel

    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

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    Quick sample code

    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
    Code:
    DoCmd.OpenReport  "rpt_MyReport", acPreview
    Here's a page where you can read up and learn other parameters if you don't want to open in preview mode.
    http://www.blueclaw-db.com/docmd_openreport.htm

  3. #3
    momani is offline Novice
    Windows XP Access 2003
    Join Date
    May 2013
    Posts
    10
    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

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

  5. #5
    momani is offline Novice
    Windows XP Access 2003
    Join Date
    May 2013
    Posts
    10
    thanks a lot this is what I need ^_^

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-27-2013, 08:54 AM
  2. Replies: 1
    Last Post: 06-10-2012, 03:41 PM
  3. Replies: 1
    Last Post: 01-10-2012, 03:44 AM
  4. Prevent Excel opening Access Tables
    By Bishop426 in forum Security
    Replies: 4
    Last Post: 09-05-2011, 09:32 AM
  5. VBA Opening Excel File and Placing Data in Cells
    By BobTHG in forum Programming
    Replies: 0
    Last Post: 01-13-2008, 03:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums