Cancel On Click Action

G

Guest

I have a command button that runs a query 'on click' and the form allows uses
to select filters by means of check buttons. Everything works fine except
that I would like the query not to run unless a check box is selected. I'm
trying the following VBA which gives the message box but doesn't stop the
query running.

If Check3 = 0 And Check5 = 0 And Check7 = 0 And Check9 = 0 Then
MsgBox "You must select at least one search criteria", vbExclamation
SentMail.SetFocus
Cancel = True
End If

Can anyone help where am I going wrong, thanks in anticipation.
 
G

Guest

Hi Allan.

I'm assuming your code below is in the button's Click event, which doesn't
have a Cancel parameter. Try replacing "Cancel = True" with "Exit Sub".

-Michael
 

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