Validation code to insure that a Control is populated (has data in it) cannot be done using an event associated with that Control. What good does having this kind of Validation code in the ctlTruckCoName_LostFocus event if the user never moves into the ctlTruckCoName_LostFocus Control? The Record can be saved without the Required data!
This type of Validation code has to be in the Form_BeforeUpdate event. Here's an example that checks for data in two Controls, but can be expanded, as needed:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.Control1,"") = "" Then
MsgBox "Control1 Must Not Be Left Blank!"
Cancel = True
Control1.SetFocus
Exit Sub
End If
If Nz(Me.Control2, "") = "" Then
MsgBox "Control2 Must Not Be Left Blank!"
Cancel = True
Control2.SetFocus
Exit Sub
End If
End Sub
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007