davidboutche
03-12-2010, 08:51 AM
I'm trying to validate a field's input and if it doesn't meet my criteria to msgbox, remove the contents and then set the focus to itself. However, the focus just moves on to the next field. Where am I going wrong?
Private Sub DOBBOX_afterupdate()
If Len(DOBBOX.Text) <> 10 Then
DOBBOX.Text = ""
MsgBox "You must complete the DOB field in the correct format dd/mm/yyyy ie 17/11/1978"
Else
If CalcAge(DOBBOX.Text) < 18 _
And UserForm1.Combo_Box_01 = "Simple Caution" Then
MsgBox ("You can't issue a simple caution to an under 18")
End If
If CalcAge(DOBBOX.Text) > 18 _
And UserForm1.Combo_Box_01 = "Youth Final Warning" Then
MsgBox ("You cannot issue a Youth Final Warning to someone over 18")
End If
If CalcAge(DOBBOX.Text) > 18 _
And UserForm1.Combo_Box_01 = "Youth Reprimand" Then
MsgBox ("You cannot issue a Youth Reprimand to someone over 18")
End If
End If
DOBBOX.SetFocus
End Sub
Private Sub DOBBOX_afterupdate()
If Len(DOBBOX.Text) <> 10 Then
DOBBOX.Text = ""
MsgBox "You must complete the DOB field in the correct format dd/mm/yyyy ie 17/11/1978"
Else
If CalcAge(DOBBOX.Text) < 18 _
And UserForm1.Combo_Box_01 = "Simple Caution" Then
MsgBox ("You can't issue a simple caution to an under 18")
End If
If CalcAge(DOBBOX.Text) > 18 _
And UserForm1.Combo_Box_01 = "Youth Final Warning" Then
MsgBox ("You cannot issue a Youth Final Warning to someone over 18")
End If
If CalcAge(DOBBOX.Text) > 18 _
And UserForm1.Combo_Box_01 = "Youth Reprimand" Then
MsgBox ("You cannot issue a Youth Reprimand to someone over 18")
End If
End If
DOBBOX.SetFocus
End Sub