Incomplete info Message Box

Gorio

Registered User.
Local time
Today, 21:07
Joined
Sep 26, 2000
Messages
33
Still learning the wonders of VB. Right now I am wondering how to have a Message box appear if the user has or is exiting a control and leaving it blank. I want the message box to return the user to the empty control once the OK is clicked.
I tried using the validation properties, but it doesn't catch the problem till you try and leave the form. I would like this to be more immediate.
 
Put this bit of code on the form Before Update Event

if isnull(me.[controlname]) then
msgbox$("Your message")
docmd.cancelevent
me.[controlname].setfocus
endif
 
I appreciate the help, but it still is not working at all, much less properly. It still moves from that box straight on to the other with no message box or any indication that it notices anything wrong.

By any chance, should it be written in a different manner for Access97?
 
This works in Access 97

You could put this in the On_Exit event or what ever event works for you in your situation:

Dim Answer As Variant

If IsNull(Me.YourControlName) Then

Answer = MsgBox("The text box can not be left blank", vbOKOnly, "Hey You!")
If Answer = vbOK Then Cancel = True
Exit Sub

Else

' Do next step

End If

If you don't need the Else just End the If and it will exit the sub when the field has data.
 
The code I wrote checks the value before you try to write the record to the database. If you want it to check before leaving the text box, you will need to use the text box On Exit event. You need to write soething to check for a valid record, since it is very annoying to have this message box appear when there is not a current record in question.
 
Thanks for the help. I ended up placing the code in the "On Enter" portion of the next control box. This seems to work better for some reason. Also made it easier to excape the form if needed.
 

Users who are viewing this thread

Back
Top Bottom