Link to home
Start Free TrialLog in
Avatar of fabi2004
fabi2004Flag for United States of America

asked on

Replacing an Access Error with a Custom Message

Could someone help me write an error handler please?  I feel like I've tried every which way and I'm just not getting the code right.

I have a button on a form that calls a Sub

Sub cmdSearch_Click
     Call Search
End Sub

Sub Search ()
    Dim strCriteria, ... ... ...
'''---lotsa code---
task = "select * from [qryFinancialsByMonth2] where (" & strCriteria & ")"
    Me.FilterOn = True
    DoCmd.ApplyFilter task
End Sub

If the strCriteria is blank when the task filter is applied, then Access says "Run-time error 3075, Syntax error missing operator in query expression..."

I'd like to replace that MsgBox with one saying "Please select at least one criteria for the search." with a simple OK button to click.

As I said, I've tried several different things.  I'm not sure any of them are worth posting.  But here's one of them:
On Error GoTo Error_Search

If IsNull strCriteria Then
MsgBox "Please select at least one criteria to search for.", vbOKOnly
End If
Exit Sub
If Err.Number = 3075 Then
Resume Exit_Sub
End If 
End Sub

Open in new window

Much appreciate any help.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fabi2004


Rey, that was fast!!!  Thank you so much!  I never hit on the right one.  I really appreciate your help.
you are welcome!