Cancel On Click Action

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
Back
Top