I have a form textbox that represents a watershed. The code is 8 digits, and under no circumstances can it be any other length. I'd like to ensure that the number entered is 8 digits long before the user can move on to another or new record.
Essentially if the # is anything but 8 digits i'd like an error message to pop-up beside the text-box "Must be 8 digits." This form element is present and set to not-visible by default. At this point the error message pops-up correctly, but it moves to the next record rather than staying focused on the textbox with incorrect data.
Should this sort of validation be in the form_BeforeUpdate event?
Code:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.HUC8) <> 8 Then
Me.txtError.Visible = True
Me.HUC8.SetFocus
ElseIf Len(Me.HUC8) = 8 Then
Me.txtError.Visible = False
End If
End Sub