Two issues: timing, and nulls.
Use the BeforeUpdate event of the control to validate it. If the entry is no
good, just cancel the event and Access won't let you out of the text box.
If nothing has been entered, the value will be Null. That's not the same as
a zero-length string: you need to test for it with IsNull().
Try something like this:
Private Sub txtDistance_BeforeUpdate(Cancel As Integer)
If IsNull(Me.txtDistance) Then
Cancel = True
MsgBox "Distance is blank", vbOKOnly,"Invalid Entry"
End If
End Sub
Notes:
1. It might be easier just to open your table in design view, select the
field, and set its Required property to Yes in the lower pane of table
design.
2. If txtDistance is a Text field (not a Number field), set the
AllowZeroLength property to No (also in the lower pane in table design).
That way you won't have to test for both IsNull() and also = "".
For more information on working with nulls, see:
Common errors with Null
at:
http://members.iinet.net.au/~allenbrowne/casu-12.html

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
>I have a text box on a form as well as an option group within a frame
> containing two option buttons. I have written code to display a message
[quoted text clipped - 11 lines]
>
> Thank you.
Wylie C - 29 Jan 2005 16:39 GMT
Thank you Allen. In conjunction with this post, the calculator is not
associated with a table, just a way the user can calculate the distance. The
code module works but now when I try to close the form, the invalid msg
appears and I end up in a loop. How would I avoid this?
> Two issues: timing, and nulls.
>
[quoted text clipped - 41 lines]
> >
> > Thank you.
Allen Browne - 30 Jan 2005 03:12 GMT
So you do want to let the user out of the text box if it's blank, but you
don't want to run the calculation if it's blank?
Then move the IsNull() text out of that event, and put it in the event where
you actually run the calculation (e.g. the Click of a button?)

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Thank you Allen. In conjunction with this post, the calculator is not
> associated with a table, just a way the user can calculate the distance.
[quoted text clipped - 50 lines]
>> >
>> > Thank you.