Docmd.OpenReport or DocmdRunReport (Available in access 2007 ??)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robtyketto
    New Member
    • Nov 2006
    • 108

    Docmd.OpenReport or DocmdRunReport (Available in access 2007 ??)

    Greetings,

    I originally used a button on a from created via the button wizard (access 2007) to run my report which was based on a query.

    Since I wanted to add some validation I removed the button and added my own
    code (as below):-

    However the open report is just a preview and the user cant exit the preview
    screen without directly using access controls.

    I cant use the DoCmd.RunReport method :-(

    I want to create report output and then use buttons on the report output
    allowing for more user navigation and functions.

    How do I run reports and allow the screen to include the actual report
    output with workable buttons etc.., as per available in the macros assigned using button wizard ?

    Hope this makes sense.

    Thanks Rob

    Code:
    Private Sub cmdopenreport_Enter()
    
    On Error GoTo Report_NoData_Error
    
    If IsNull(cboStudentid) Then
            MsgBox "Please choose a student Id", vbCritical
            cboStudentid.SetFocus
    Else
        DoCmd.OpenReport "rptStudentClassification", acViewPreview
       ' DoCmd.RunReport "rptStudentClassification"
    End If
    
    Report_NoData_Exit:
    Exit Sub
    
    Report_NoData_Error:
    If Err.Number = 2501 Then 'the report was cancelled
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Report_NoData_Exit
    End If
    
    
    End Sub
  • robtyketto
    New Member
    • Nov 2006
    • 108

    #2
    I should add using DoCmd.RunReport "rptStudentClas sification" gave the message

    "Compile Error: Method or data member not found" though this code works:-

    DoCmd.OpenRepor t "rptStudentClas sification", acViewPreview

    Indicating the report is fine.

    Thanks
    Rob

    Comment

    • robtyketto
      New Member
      • Nov 2006
      • 108

      #3
      Further clarification of problem:-

      In access 2007 using the button wizard you can assign a report to run it
      upon click event (macro).

      Rather than seeing the preview window with magnifying glass you see the
      report output.
      Within the report layout you can add buttons to it and assign code.

      The buttons on my report can be seen using openreport, but as its in preview
      mode they cant be clicked.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32668

        #4
        Let's start with a couple of simple things :
        1. DoCmd has no .RunReport method. It DOES have .RunCommand, .RunMacro and .RunSQL methods. It also has a .OpenReport method.
        2. Reports don't have clickable Command Buttons. They can exist, but are not clickable (Why? I don't know).

        Perhaps #2 is not so simple then I suppose.
        I can only guess that they are there as Reports and Forms share a lot of similarities. Maybe someone else knows better.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32668

          #5
          It looks like what you're looking for is actually to run the selecting etc from a form before opening the Report. Example Filtering on a Form gives some help with this concept. It works mainly with Forms but the concepts are the same.

          Comment

          Working...