erratic preview, email, and print report

pnmng49

Registered User.
Local time
Yesterday, 20:47
Joined
May 31, 2008
Messages
16
I have a form with three command buttons to preview, email, and print a report. The code works---sometimes!!. It is erratic, sometimes the preview code won't open the report. Here is the coode, can you help, please?

Code:
Private Sub cmdOpenPreviewStatusReport_Click()
On Error GoTo Err_cmdOpenPreviewStatusReport_Click

    Dim stDocName As String

    stDocName = "rptStatusReport"
    'DoCmd.Close acReport, stDocName, acSaveYes
    DoCmd.OpenReport stDocName, acViewPreview
    cmdMailStatusReport.Visible = True
    
Exit_cmdOpenPreviewStatusReport_Click:
    Exit Sub[code/]

Err_cmdOpenPreviewStatusReport_Click:
    'MsgBox "Cancel."
    Resume Exit_cmdOpenPreviewStatusReport_Click
    
End Sub[code/]

'report on open event
Private Sub Report_Open(Cancel As Integer)
    DoCmd.MoveSize 200, 200
    Dim strTableName As String
    Dim strSQL As String
    
    strTableName = InputBox("Enter the month/year for the Status Report. Ex: jan08")
    strSQL = "SELECT * FROM "
    strSQL = strSQL + strTableName + ";"
    
    Me.RecordSource = strSQL
    Reports!rptStatusReport.Caption = "Status Report   " + strTableName
End Sub

'report close event
Private Sub Report_Close()
    'Me.RecordSource = " "
    Forms!frmValidationsTracker!cmdOpenPreviewStatusReport.SetFocus
    Forms!frmValidationsTracker!cmdMailStatusReport.Visible = False
End Sub

'email report button
Private Sub cmdMailStatusReport_Click()
' Prevent error screen if user cancels without sending mail.
    On Error Resume Next

    Dim stDocName As String
    Dim strToWhom     As String   '<---sets up a variable object for who we are going to send out email to
    Dim strMsgBody    As String   '<---sets up a variable object for the body of our email
    stDocName = "rptStatusReport"
    strToWhom = InputBox("Enter recipient's e-mail address.", _
                        "Enter Email Address")   '<--- uses an input box to ask the user what email address to send this message to
      
    strMsgBody = stDocName
    
    ' Provide Subject title bar and message text.
    DoCmd.SendObject acReport, stDocName, acFormatRTF, strToWhom, , , "Status Report", strMsgBody, True
    Forms!frmValidationsTracker!cmdMailStatusReport.Visible = False
    DoCmd.Close acReport, "rptStatusReport"
End Sub[code/]
 
Last edited:
have you checked to make sure that, in the event that the preview does not work, that it's not actually a case of the query returning no records?

you can probably check for this easily by putting in a message box in the "no data" event of the report - and see if it is triggered in those instances.
 

Users who are viewing this thread

Back
Top Bottom