If you put it in the before update and set Cancel = True if it is invalid, the focus won't leave the control after your warning message. You could use another event and setfocus to the control and do a ctlname.Undo to clear the change. In general, the code for testing Number, Date and String are as follow, where I've allowed number or date entry but cancel (Before Update event only) if it is a text string.
If Len(Me.nametxtbox & "") Then
If IsNumeric(Me.nametxtbox) Then
MsgBox "Is a number"
ElseIf IsDate(Me.nametxtbox) Then
MsgBox "Is a date"
Else
MsgBox "Is text"
Cancel = True
End If
Else
MsgBox "Is empty"
End If
You could test for null rather than length of the control contents & "" but this works fine. The length test is for the case where a control had a value which has now been deleted though one is required.
Ciao
Jürgen Welz
Edmonton AB Canada
[email protected]