DoCmd.OpenReport Problem or Limitation?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scottbouley
    New Member
    • Sep 2008
    • 30

    #1

    DoCmd.OpenReport Problem or Limitation?

    Maybe I'm missing something or perhaps there's another way to do this. I'm trying to allow the user to preview and print an invoice as they are exiting from the New Sale form. However, the preview opens but closes after a second. Can anyone give me a clue?

    Thanks

    Code:

    Code:
    If MsgBox("Do You Want To Create An Invoice?", vbDefaultButton1 + vbYesNo) = vbYes Then
                Dim stDocName As String
                stDocName = "rpt_Invoice"
                DoCmd.OpenReport stDocName, acViewPreview
            Else
            End If
            
            DoCmd.Close acForm, "frm_New_Sale", acSaveNo
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    If the report depends on data that you've just entered in your record, my guess would be because the report has no data. If this is the case, you need to save the record before opening the report:

    Code:
    If MsgBox("Do You Want To Create An Invoice?", vbDefaultButton1 + vbYesNo) = vbYes Then
                Dim stDocName As String
                If Me.Dirty Then Me.Dirty = True
                stDocName = "rpt_Invoice"
                DoCmd.OpenReport stDocName, acViewPreview
            Else
            End If
            
            DoCmd.Close acForm, "frm_New_Sale", acSaveNo
    Welcome to Bytes!

    Linq ;0)>

    Comment

    • scottbouley
      New Member
      • Sep 2008
      • 30

      #3
      If I change the DoCmd.OpenRepor t to acViewNormal it prints with data. If I modify the close form code so that it errors out, the report stays up with the data.

      Comment

      • DonRayner
        Recognized Expert Contributor
        • Sep 2008
        • 489

        #4
        Originally posted by scottbouley
        If I change the DoCmd.OpenRepor t to acViewNormal it prints with data. If I modify the close form code so that it errors out, the report stays up with the data.
        maybe something in the forms on close event is causing this. Why not set your break points and follow the code through it's execution to see what's hapening.

        Comment

        • mshmyob
          Recognized Expert Contributor
          • Jan 2008
          • 903

          #5
          It could be as Linq says. It may have to do with no data be generated. In preview mode the events of the report's sections do not activate. Preview mode will not give the same results as print mode if the data is based on events of the report sections. Could this have something to do with it?

          cheers,

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            Linq,

            What did you intend your line #3 to do?

            Comment

            Working...