'no data' problem!?

J

Jerome

Hi,

I've got problems with a report when it has no data!

I tried using the CancelEvent but I still get an error message ("The
OpenReport has been canceled", although my code contains
DoCmd.SetWarnings False??) which, if the application is launched in
run-time mode, will crash it!?

Is there a way to test if there's data before launching the report? Or
how could I circumvent this error message?

Thanks a loT!

Jerome
 
R

Roger Carlson

You need to trap for that error in the code that has the OpenReport. (Is it
a button?) It would look something like this:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

Dim stDocName As String

stDocName = "rptYourReport"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdPreview_Click
End If

End Sub


On my website (www.rogersaccesslibrary.com), is a small Access database
sample called "NoDataInReports.mdb" which illustrates this.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top