On no data

  • Thread starter Thread starter jeanulrich00
  • Start date Start date
J

jeanulrich00

Hi

I have a button on a form that open a report

As I don't want that the report open when there is no data, I have
used a small script on the OnNoData event of the report

I just add msgbox "Sorry there is no data"

Here is the problem

When I click on the button to open the report, when there is no data,
The message box open telling "Sorry there is no data" I click on the
OK button and the same message box open a second time "Sorry there is
no data". I click a second time on OK and then the report opens with
no data.

What I want is when there is no data, message box open "Sorry there is
no data" and then when I click on OK no action occur, like if the code
stop and I am back on the form.

Thanks
 
Set the return value of the Cancel argument to True in the report's NoData
event procedure. This cancels the opening of the report:

Private Sub Report_NoData(Cancel As Integer)

MsgBox "Sorry there is no data.", vbInformation, "Report Cancelled"
Cancel = True

End Sub

When opening the report from the form you'll need to handle the error which
cancelling the report raises:

Const REPORTCANCELLED = 2501

On Error Resume Next
DoCmd.OpenReport "YourReport"
Select Case Err.Number
Case 0
' no error
Case REPORTCANCELLED
' anticipated error so do nothing
Case Else
' unknown error so inform user
MsgBox Err.Description, vbExclamation, "Error"
End Select

Ken Sheridan
Stafford, England
 
Where are you testing for data?

It is possible to have the OpenReport command canceled on no data.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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

Back
Top