OnNoData event

L

Leslie Isaacs

Hello All
I have a form which, when it is opened, I would like a report called "rpt
locum confirmation notice outstanding" to be opened - but only if there is
data for that report. I have set the OnNoData event for the report to:

Cancel=True

.... and I have set the OnOpen event of the form to:

Private Sub Form_Open(Cancel As Integer)
Dim stDocName As String
stDocName = "rpt locum confirmation notice outstanding"
DoCmd.OpenReport stDocName, acPreview
On Error Resume Next
If Err = 2501 Then Err.Clear
On Error Resume Next
End Sub

.... but I find that when there is no data for "rpt locum confirmation notice
outstanding" I still get the error 2501 message.

What have I done wrong?
Hope someone can help

Many thanks
Leslie Isaacs
 
G

Guest

Your On Error is not in the right place. Move it before the OpenReport. The
way you have it written, the error occurs before it gets to the On Error
statement.

Also, notice I cleaned up your code to make it easier to read. Good
indentation helps, and one line If statements can be confusing as well.

Private Sub Form_Open(Cancel As Integer)
Dim stDocName As String

stDocName = "rpt locum confirmation notice outstanding"
On Error Resume Next
DoCmd.OpenReport stDocName, acPreview
If Err = 2501 Then
Err.Clear
End If
 

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