Unanswered: Trapping errors when no query criteria is given in MS Access
I want to trap errors and present a message if the user clicks the "Print" button without a query criteria. At the moment I only get a run-time syntax error message which has a "debug" button for accessing the entire code. I want a custom message that will hide the code say "Sorry, there was no search criteria".
By the way, the database does not open preview of reports, clicking the PRINT button only sends the report to the printer.
This is the code for printing:
Private Sub cmdPrint_Click()
Dim varWhere As Variant
varWhere = BuildFilter
' Update the record source
Me.RecordSource = "SELECT * FROM q_Vehicles " & varWhere
' Requery the form
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = "" Else
'The WHERE clause does NOT need the word "WHERE"
' strip off "WHERE " in the filter
varWhere = Mid(varWhere, 7)
End If DoCmd.OpenReport "rpt_Vehicles", acPreview, , varWhere