My Code and “On No Data” event clashing

David Ball

Registered User.
Local time
Tomorrow, 05:28
Joined
Aug 9, 2010
Messages
230
Hi,
The code below works to open a report (after some help from PBaldy).

Private Sub CmdSubsystem_Click()
If IsNull(TxtSubsystem.Value) Then
MsgBox "You did not enter a Subsystem number", vbOKOnly + vbDefaultButton2 + vbCritical, "No Criteria Entered"
Else
DoCmd.OpenReport "rptTESTInfoBySubsystem", acViewReport, "qryTestDetailsBySubsystem", " Subsystem = '" & TxtSubsystem.Value & " ' "
End If
End Sub

I have an On No Data event set up on the report to show a message and Cancel the report if there is no data returned. See below:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No PAS Serial Test Related to Subsystem Entered", vbCritical, "No Data Found"
Cancel = True
End Sub

The problem is if there is no data, the message shows and when I select OK it shows this error:

Run-time error ‘2501’:
The openreport action was canceled.

What do I need to change to get this working so that after I press OK the report (with no data) doesn’t open and no error occurs?
Thanks very much
Dave
 
Thanks for that. I don't really understand this code so have just pasted it into my code. I still can't get it working.

I have placed this code in the reports On No Data event code. Is this correct, or should it be in my code for the commandbox On Click event?

Thanks very much

Dave
 
It needs to be in the code of the command button.
 

Users who are viewing this thread

Back
Top Bottom