Help! My If Then Syntax is wonky!

Wag2016

Registered User.
Local time
Yesterday, 22:00
Joined
Mar 5, 2016
Messages
24
Thanks for your help - I am new to VBA syntax. I have found a nifty solution to addressing a required field on a form, I am just having a problem adapting it so that I can have more than 1 control. For reference, I have 8 checkboxes that must be checked off before the record can be saved.


The code:

Code:
 For Each ctl In Me.Controls
        If Check1.Tag = "reqd" And Nz(Check1.Value, "") = "" Then MsgBox Check1.Name & " has not been checked off." & vbCrLf & vbCrLf & "Have you verified the correct date is shown?", vbCritical, "Error!"
        ctl.SetFocus
        Cancel = True
        End If
   Exit Sub
  
   Next ctl
        If Check2.Tag = "reqd" And Nz(Check2.Value, "") = "" Then MsgBox Check2.Name & " has not been checked off." & vbCrLf & vbCrLf & "Have you verified that the Location is correct?", vbCritical, "Error!"
        ctl.SetFocus
        Cancel = True
        End If
    Exit Sub

I have an error that says End if without block if.

Thank you!
 
I think you want something more like:

Code:
 For Each ctl In Me.Controls
        If ctl.Tag = "reqd" And Nz(ctl.Value, "") = "" Then 
          MsgBox Check1.Name & " has not been checked off." & vbCrLf & vbCrLf & "Have you verified the correct date is shown?", vbCritical, "Error!"
          ctl.SetFocus
          Cancel = True
          exit sub
        End If
Next ctl
 

Users who are viewing this thread

Back
Top Bottom