Set a warning if all text boxes on a form have not been filled in

C

Chris Z

I am setting up a form and I want to require all the text boxes to be filled
in. If I use a validation rule, it only works if somthing is entered into the
text box. I need the validation rule to work if the text box is tabbed or
entered and exited without an entry. Is there a better way to do this with a
macro?
 
J

Jae

To do it for a lot of fields, this method would be a pain, but if it's just 1
or 2 fields, you could try this method (I know you asked for macro, but
actually do it in a VBA is a lot simpler):
For "On Lost Focus" event put:

if isnull (me!YourFieldHere) or me!YourFieldHere = "" then
msgbox "You cannot have this field empty"
me!YourFieldHere.setfocus
end if

I haven't tested the code. Let me know if it works or not.
 
J

John W. Vinson

On Tue, 12 Aug 2008 08:30:18 -0700, Chris Z <Chris
I am setting up a form and I want to require all the text boxes to be filled
in. If I use a validation rule, it only works if somthing is entered into the
text box. I need the validation rule to work if the text box is tabbed or
entered and exited without an entry. Is there a better way to do this with a
macro?

Use the Form's BeforeUpdate event to check this. A field validation rule will
not work, since as you have seen, the user can simply not touch the field.

You can (instead, or also) go into Table Design view and set each such field's
Required property to Yes.
 
F

fredg

I am setting up a form and I want to require all the text boxes to be filled
in. If I use a validation rule, it only works if somthing is entered into the
text box. I need the validation rule to work if the text box is tabbed or
entered and exited without an entry. Is there a better way to do this with a
macro?

You can use code in the form's BeforeUpdate event.
Assuming you only wish to check the controls in the form's Detail
Section and that only Text boxes or Combo boxes are used:

Dim C As Control
For Each C In Me.Section(0).Controls
If TypeOf C Is TextBox or TypeOf C is Combobox Then
If IsNull(C) Or C = "" Then
MsgBox "All boxes must be filled in."
Cancel = True
End If
End If
Next
 
T

tuesamlarry

I had the same problem, and came up with the following solution:
I set up an input mask for the text box. Knowing that using a tab key could
simply pass through the text box without an entry, I therefore created a 2
line macro and put it in the OnLoad event of the form. The macro sends a
character to the text box I require an entry in, and then I erase it with the
second macro line. By sending a key to the text box, the input mask is turned
on and won't let you leave until you put in a valid entry. This works great
for me. You can't pass through the text box now without a valid entry.
Tuesamlarry
 

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

Similar Threads

Validate a Date 1
Validation Rule/Text 1
Validation on text 2
Save New Record from Form 2
After crash form errors. 1
Validation Rules for a Control on a Form (?) 4
validation rule question 6
Empty TextBox 1

Top