We help IT Professionals succeed at work.

Replacing an Access Error with a Custom Message

fabi2004
fabi2004 asked
on
96 Views
Last Modified: 2017-04-10
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
'''...
Error_Search:
If Err.Number = 3075 Then
Resume Exit_Sub
End If 
End Sub

Open in new window


Much appreciate any help.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Rey, that was fast!!!  Thank you so much!  I never hit on the right one.  I really appreciate your help.
CERTIFIED EXPERT
Top Expert 2016

Commented:
you are welcome!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions