Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel the extra message boxes when using Lebans Print to PDF and no data

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
I use Lebans ConvertReportToPDF module to produce PDF's of my reports and would like to tidy up the process when there is no data in the report.

I use a button on a form to start the process
Code:
Private Sub CmdReporttoPDFNoPreview_Click()
' Save the Report as a PDF document but with no preview.
Dim blRet As Boolean
blRet = ConvertReportToPDF(Me.[ReportName], vbNullString, _
"" & Me.[SaveAs] & ".pdf", False, False, 150, "", "", 0, 0, 0)
End Sub

The report has NoData coding
Code:
Private Sub Report_NoData(Cancel As Integer)
  
MsgBox "There are currently no records available for this report."
Cancel = True
If Err = 2501 Then Err.Clear
      
End Sub

and the ConvertReportToPDF is Leban's standard module.

The problem is when there is no data I get:
A message box which says "printing now outputting..." then another MsgBox "There are currently no records available for this report." which then stops the process until I click OK and then the 1st 2 boxes disappear and I get another message box saying "The OutputTo Action was cancelled" and I have to again click OK. There is no error code on this last message box.

Does anyone know how I can stop the 1st and last message box just to be left with "There are currently no records available for this report."

Thanks in advance for any suggestions or help.


 
You might try adding some error handling in the calling sub.
Code:
Private Sub CmdReporttoPDFNoPreview_Click()
       On Error GoTo CmdReporttoPDFNoPreview_Click_Error

    [COLOR=#4E9A06]' Save the Report as a PDF document but with no preview.[/color]
    Dim blRet As Boolean
    blRet = ConvertReportToPDF(Me.[ReportName], vbNullString, _
        "" & Me.[SaveAs] & ".pdf", False, False, 150, "", "", 0, 0, 0)

    Exit Sub

cmdFlagChart_Click_Error:
    If Err.Number =2501 Then
        Resume Next
    End If
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Getting a compile error, label not defined
 
My bad in the copy paste. This is the type of error that you should eventually be able to trouble-shoot and correct. Compiling should point out the exact line causing the error. The expression needs to match with an expression in another line. My "cmdFlagChart..." reference was a hangover from my existing code. There may be other errors ;-)

Code:
Private Sub CmdReporttoPDFNoPreview_Click()
    On Error GoTo CmdReporttoPDFNoPreview_Click_Error

    [COLOR=#4E9A06]' Save the Report as a PDF document but with no preview.[/color]
    Dim blRet As Boolean
    blRet = ConvertReportToPDF(Me.[ReportName], vbNullString, _
        "" & Me.[SaveAs] & ".pdf", False, False, 150, "", "", 0, 0, 0)

    Exit Sub

CmdReporttoPDFNoPreview_Click_Error:
    If Err.Number =2501 Then
        Resume Next
    End If
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Hi Duane, thank you for the suggestion but it doesn't stop the message boxes. I think I am going to try an IIF Dcount to run before the report opens and cancel if no records.
 
Given up on the IIF idea, too much pain, not enough gain. Will put up with the extra message boxes for the time being.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top