I'm using the following code, has worked fine on the beforeupdate on a forms control. Problem is I'm trying to use this as validation on a command button. When the command button is selected I want the code to go through and validate the fields in which the tag property is set at "required". When I run this it errors at Cancel = true, variable not defined.
Is there anyother method to validation on a command button.
Private Sub cmdSaveandmail_Click()
Dim blnContinue As Boolean
Dim ctl As Control
blnContinue = True
For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If IsNull(ctl) Then
MsgBox "Required Information Missing", vbCritical + vbOKOnly + vbDefaultButton1, "You must fill in the field indicated with red"
Cancel = True
ctl.SetFocus
Exit For
End If
End If
Next ctl
Set ctl = Nothing
end sub
Is there anyother method to validation on a command button.
Private Sub cmdSaveandmail_Click()
Dim blnContinue As Boolean
Dim ctl As Control
blnContinue = True
For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If IsNull(ctl) Then
MsgBox "Required Information Missing", vbCritical + vbOKOnly + vbDefaultButton1, "You must fill in the field indicated with red"
Cancel = True
ctl.SetFocus
Exit For
End If
End If
Next ctl
Set ctl = Nothing
end sub