Share via

Opening a report using a command button

Anonymous
2010-10-18T21:56:15+00:00

How can I open a report using a command button. The report opens from the navigation pane using the open command, but when I create a command button, the button will not open the report.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2010-10-19T20:42:55+00:00

    Hello and thanks for the response. This is what I thought was happening

    However, after correcting the code it still does not do what I am looking for. What happens now when the command button is selected is the report runs the underlying query (which is good), but it sends the report directly to the printer. I need to have the report open to the screen so I can select, copy and paste to another application.

    Thanks for your help.

    DoCmd.OpenReport stDocName, acPreview

    Intellisense is our friend, when you first type in the command after hitting the space bar, Intellisense will show all the arguments for the command with suggestion on how what to enter. There is also the Help screens. Looking up Open Report will show you the parameters for the command.


    Hope this helps, Scott<> P.S. Please post a response to let us know whether our answer helped or not. Microsoft Access MVP 2009 Author: Microsoft Office Access 2007 VBA Technical Editor for: Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports and Queries

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-10-19T20:07:45+00:00

    Hello and thanks for the response. This is what I thought was happening

    However, after correcting the code it still does not do what I am looking for. What happens now when the command button is selected is the report runs the underlying query (which is good), but it sends the report directly to the printer. I need to have the report open to the screen so I can select, copy and paste to another application.

    Thanks for your help.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-10-19T14:33:51+00:00

    You're missing a line of code (plus a declaration). It should be:

    Private Sub Command30_Click()

    On Error GoTo Err_Command30_Click

    Dim stDocName As String

      stDocName = "Members Email Report"

      DoCmd.OpenReport stDocName

    Exit_Command30_Click:

      Exit Sub

    Err_Command30_Click:

      MsgBox Err.Description

      Resume Exit_Command30_Click

    End Sub

    It looks as though there may be a bug in the wizard, because I just had the incorrect code generated in Access 2007 myself.


    Doug Steele, Microsoft Access MVP

    http://www.AccessMVP.com/djsteele (no e-mails, please!)

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-10-19T14:19:44+00:00

    What's the code behind the button?

    "Dennis719" wrote in message news:Email removed for privacy .com...

    How can I open a report using a command button. The report opens from the navigation pane using the open command, but when I create a command button, the button will not open the report.


    Regards, Graham R Seach Sydney, Australia

    Here is the code when I use the the command button wizard.

    Private Sub Command30_Click()

    On Error GoTo Err_Command30_Click

        stDocName = "Members Email Report"

    Exit_Command30_Click:

        Exit Sub

    Err_Command30_Click:

        MsgBox Err.Description

        Resume Exit_Command30_Click

    End Sub

    Thanks for your help.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2010-10-18T22:06:36+00:00

    What's the code behind the button?

    "Dennis719" wrote in message news:*** Email address is removed for privacy *** .com...

    How can I open a report using a command button. The report opens from the navigation pane using the open command, but when I create a command button, the button will not open the report.


    Regards, Graham R Seach Sydney, Australia

    Was this answer helpful?

    0 comments No comments