Reports with no records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have set up a form into which the user will enter two dates. On clicking
the 'Run Report' button a report is opened that has the code in the NoData
event to display a message box and then cancel the operation. Fine!! So far
so good.

After clicking the OK button a further message box displays saying that the
opening of the report has been cancelled and asks the user to click an OK
button for the second time. I can't find the coding for this message box. Any
ideas where it's likely to be. Also is there a quick way to search all the
VBA code for an application.

Kind regards

Tony
 
Your code probably uses OpenReport, and if the report it canceled, it will
be notified with error 2501. Add error handling to this routine so that it
ignores the error.

This kind of thing:

Private Sub cmdRunReport_Click()
On Error Goto Err_Handler:
DoCmd.OpenReport "Report1", acViewPreview
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description
End If
Resume Exit_Handler
End Sub


If error handling is a new concept, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 
Allen

Thanks so much for your help. Spot on.

When I started building this database my knowledge of Access was sparse to
say the least but, thanks to people like you, I've come a very long way quite
quickly.

Whilst the concept of error handling isn't new to me the logistics of it
are. I've had a brief look at your website and you can be rest assured I
shall be going through it in much finer detail very shortly.

Thanks for your time and expertise.

Kind regards

Tony
 
Back
Top