Mandatory fields/text boxes in a form

M

Mark

Hi,
I am working on a form and need some help. I would like
my form to "require" the user to input a value for a
couple of the fields (I have a couple of text boxes that
are either text or a date). And if the user tries to move
to the next field without entering any data (either by
using the tab or enter key) a pop up window comes up
stating that the field needs to be filled out before
moving onto the next field in the form. I know how to
make a field required, but I am having trouble with
prompting the user with a dialog box. Am I close in
saying that I should go into the text box where I want to
require the user to input data... and under Event... place
some code in ValidationRule?... I've tried something like:
IsNull ...and then writing out my message in the
Validation Text box. But I am obviously doing something
wrong.

Can you assist me? Thanks, Mark
 
H

HSalim

Mark,
Use events -
go to the control's properties
in the After update, select event procedure in the dropdown,
click on the ellipsis (...)
and enter this code
(I'm assuming you have named the control TxtOrderDate)

if (isnull(me.txtOrderdate) orme.txtOrderDate = "") then
msgbox "you must enter a valid date here before you can proceed"
end if

This does not precent the user from moving out of the control though
so add this code to the exit event as well
if (isnull(me.txtOrderdate) orme.txtOrderDate = "") then
msgbox "you must enter a valid date here before you can proceed"
end if
 
N

Nick Mirro

Is there a way to prevent this message for old records. i.e. if they open
an old record with a missing field, I would not want them to be prompted.
Only when creating a new record and forgetting to complete it.

Nick
 
K

Kevin

I do something similar using a flag on the form. If the
flag is set, the record is a new record and validate the
form data, if it is not set, then don't validate.

Hope this helps!

Kevin
 
M

MDW

I assume you have a button somewhere on your form that
creates a new record. In the Click() event for that
button, set a variable called blnNewRec to True (blnNewRec
would have to have form scope).

Then, in the LostFocus event of the checkbox, put this:

If (txtDate.Text = "" Or IsDate(txtDate.Text) = False) And
blnNewRec = True Then

MsgBox "You must enter a valud date!"
txtDate.SetFocus

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top