As to the
I can't seem to get it to go back to focus on the Contact field
this is one of those quirks of Access. The focus both
has and
hasn't actually left the field in question when the
LostFocus event fires. The way to beat this, as Mike TheBike has suggested, is to use the
BeforeUpdate event and use the line
Cancel = True
The problem with using the
BeforeUpdate event of the
textbox for this kind of validation is that the user can simply
not enter the textbox at all, in which case the validation won't take place at all! You need to place the code in the form's
BeforeUpdate. This will insure that the user has to fill in the data.
- Private Sub Form_BeforeUpdate(Cancel As Integer)
-
If IsNull(Me.Contact) Then
-
MsgBox "This field must be filled in!"
-
Cancel = True
-
Me.Contact.SetFocus
-
End If
-
End Sub
-
This is true for data validation that is intended to insure that
a given field is populated before saving the record . Validation that is intended to insure that
data entered into a field complies with some criteria, such as an ID number containing only numeric characters or a description field only containing alpha characters, can be placed in either the
BeforeUpdate event of the textbox or the form.
Linq
;0)>