Required Fields for New Form/Record

G

Grasavong

I created a form where all fields are required to have data in it. I used the
BeforeUpdate event procedure to tell the user if the field has not been
entered. The code works but only if the user goes back and updates the field.

I need a code where it can be run on the initial entry of a new form. If the
user puts their cursor in the text box and tabs or clicks into another text
box without entering in the first text box, I want a msgbox to tell them or
at least tell them when they attempt to the save the record.

I've used the validation rule, Onload, Onclick...BeforeUpdate is the only
thing that works in the way I'd like it to.

Is this possible?
-Thanks
 
A

Allen Browne

Use the BeforeUpdate event of the *form* (not of the controls.)

Alternatively, open the table in design view (the one this form gets its
records from), and set the Required property to yes for each field.
 
G

Grasavong

Thank you Allen,
I did what you suggested and it works great for new records. If anyone
starts a new record and tries to save, a message will come up to tell the
user if any empty fields are not completed.

However, the rule doesn't work when it comes to existing records. If someone
needs to update an existing record and leaves a field blank, I want a message
warning the user that they need to complete this field before they are able
to update the record. I figured that since the required property is turned to
'yes' it would tell the user to complete the field?

Thank you,
Gwen
 
A

Allen Browne

Right: when you make the change in Table Design, it asks if you want to test
existing data.

Form_BeforeUpdate should work for this case.
 
L

Linq Adams via AccessMonster.com

This example shows how to do this for new and existing records:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion +
vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
Me.Undo
End If
Else
If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo +
vbDefaultButton1, "Save This Record ???") = vbNo Then
Me.Undo
End If
End If
End Sub

BTW, you cannot use validation code intended to ensure that a textbox has
data in it by tying it to an event of the textbox, for the simple reason that
the user may not enter the textbox at all! Then your code would be useless.
 

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