Required Fields in a Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Do you always have to set the property for a Required field in the table? I
have a command button that I would like to use to fire a Required fields
error message, if the required fields have not all been filled in. This
would be instead of having each individual required field generate the error
message if you leave it blank.

Is this possible?

Thanks,
 
From the information provided, it is certainly possible. The code for the
button would check for entry into the required fields and provide an error
message as necessary, as you suggested.

However, many would agree that is a bit dangerous from a data integrity
point of view. By not enforcing required entry at the table level, you leave
open a multitude of oppurtunities for data integrity to be violated. For
instance, if a user were to close the form after entering some information
without clicking the button, fields that you intended to be required would be
blank.

I would consider the benefits of having "one error message" against the
value of ensuring data integrity.

HTH.
 
Thanks - I will go with ensuring data integrity, and set the property at the
table level.
 
A safe alternative might be to use the Validation Rule of the table, instead
of the Required property of each field.

In table design view, open the Properties box (View menu), and locate the
Validation Rule there (not in the lower pane of table design.) Set the
Validation Rule to something like this:
([Surname] Is Not Null) AND ([City] Is Not Null) AND ...

You will then receive the message when the record is about to be saved,
instead of when you visit each field.

An alternative is to use the BeforeUpdate event of the form (not control)
where the user enters information, but this suffers from the problems
"darrep" raised.
 
In table design view, open the Properties box (View menu), and locate the
Validation Rule there (not in the lower pane of table design.) Set the
Validation Rule to something like this:
([Surname] Is Not Null) AND ([City] Is Not Null) AND ...

I tried this validation rule in my "Tracker_be" file table. I'm using a form
in "Tracker_fe" file to enter the data. I populated one of the required
fields and left the rest blank. Then I have a Save and Close button on the
form. When I click the button, the form closes and the populated data is
written to the table. I do not get an error message.

I would like an error message to pop up and indicate which or All fields are
required and then leave the form open and move the cursor to the first
unpopulated required field.
How do I do this?

Allen Browne said:
A safe alternative might be to use the Validation Rule of the table, instead
of the Required property of each field.

In table design view, open the Properties box (View menu), and locate the
Validation Rule there (not in the lower pane of table design.) Set the
Validation Rule to something like this:
([Surname] Is Not Null) AND ([City] Is Not Null) AND ...

You will then receive the message when the record is about to be saved,
instead of when you visit each field.

An alternative is to use the BeforeUpdate event of the form (not control)
where the user enters information, but this suffers from the problems
"darrep" raised.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

darrep said:
From the information provided, it is certainly possible. The code for the
button would check for entry into the required fields and provide an error
message as necessary, as you suggested.

However, many would agree that is a bit dangerous from a data integrity
point of view. By not enforcing required entry at the table level, you
leave
open a multitude of oppurtunities for data integrity to be violated. For
instance, if a user were to close the form after entering some information
without clicking the button, fields that you intended to be required would
be
blank.

I would consider the benefits of having "one error message" against the
value of ensuring data integrity.

HTH.
 
If you use the Close action (in a macro or in code) to close a form when
some required fields are left blank, Access does allow the form to close
WITHOUT ANY WARNING that you lost the incomplete record. IMO, that's a
pretty serious bug in Access:
http://allenbrowne.com/bug-01.html
The article suggests how to avoid this, by explicitly saving the record in
your macro/code before you use Close.

If you want a list of the required fields rather than a generic "can't save"
error message, you will need to write some code in the BeforeUpdate event of
the form. For code that identifies the requried fields, you could adapt the
code from the sample database in this article:
Highlight the required fields, or the control that has focus
at:
http://allenbrowne.com/highlight.html


--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Whitney said:
In table design view, open the Properties box (View menu), and locate the
Validation Rule there (not in the lower pane of table design.) Set the
Validation Rule to something like this:
([Surname] Is Not Null) AND ([City] Is Not Null) AND ...

I tried this validation rule in my "Tracker_be" file table. I'm using a
form
in "Tracker_fe" file to enter the data. I populated one of the required
fields and left the rest blank. Then I have a Save and Close button on the
form. When I click the button, the form closes and the populated data is
written to the table. I do not get an error message.

I would like an error message to pop up and indicate which or All fields
are
required and then leave the form open and move the cursor to the first
unpopulated required field.
How do I do this?
 
Back
Top