How to display a msgbox when Report returns null value.

MsLady

Traumatized by Access
Local time
Today, 00:46
Joined
Jun 14, 2004
Messages
438
I have a report based on a query QryEmployeebyState. A parameter collects the state and displays the Employees that matches that state.
Let's say a user enters a zipcode and there is no match for that state.

My report displays #Error.
Instead of this, I want my report to display a msgbox that informs the user that record does not match.

How do i achieve this? :)
 
In your report :

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Data.", vbInformation
Cancel = True
End Sub

In your form :

On Error GoTo Err_cmdPrint_Click

'your command to opent report

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
If Err = 2501 Then
' this number is no data error
Else
MsgBox Err.Description
End If
Resume Exit_cmdPrint_Click

==========
office 2k2
 
Thanks nyoman, this works perfectly! :)

God bless you.
 

Users who are viewing this thread

Back
Top Bottom