Null query

  • Thread starter Thread starter Lori
  • Start date Start date
L

Lori

I'm running a query using the docmd in the before update
event in a text box on a form. If the query is null I
want it to close right away or never open at all.

I tried using a report instead and setting the OnNoData
event to cancel but I get an error 2501 that I can't seem
to capture.

Thanks in advance for your help.

Lori
 
You must capture the 2501 error in the code that opens the report, not in
the report.
 
How do I do that? Here is my docmd line.
DoCmd.OpenReport stDocName, acViewPreview, , ,
acWindowNormal

Thanks
 
Pardon me for jumping in,

In the OnNoData event of the report you need code like:

MsgBox "No data to print!!"
Cancel = True

Your print button should have code that looks something like:

Private Sub cmdPrint_Click()
On Error GoTo cmdPrint_Error '<<<-----Note

docmd.OpenReport "myReport", acViewNormal

Exit Sub

cmdPrint_Error: '<<<-----Note
If Err.Number = 2501 Then '<<<-----Note
'do nothing this is a user cancelled action
Else
MsgBox Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Problem"
End If

End Sub
 
Back
Top