Field Property "Required"

J

Jim Normile

IF the user doesnt complete a required field, then an error message displays,
which is not user friendly. I need to customise the error message to say
something like "You must complete the Surname field before this record can be
saved".
Any advice please??
Jim
 
A

Allen Browne

A simple way to do this is to set the Required property of the field in the
table to No.

Instead, set the Validation Rule to:
Is Not Null
and you can then set the Validation Text to whatever you want.

To trap the error at the form level instead, use the Error event of the
form. Set up your own error message, and set the Response argument to
acDataErrContinue.
 
T

Tim Ferguson

IF the user doesnt complete a required field, then an error message
displays, which is not user friendly. I need to customise the error
message to say something like "You must complete the Surname field
before this record can be saved".

You can use the BeforeUpdate event of the form, along the lines of

private sub Form_BeforeUpdate( cancel as integer)

if isnull(txtSurname) then
' warn the user
msgbox "you have to fill in the surname, stoopid!"
' send the user back to the correct control
txtSurname.SetFocus
' and prevent the form going ahead with the update
Cancel = True

elseif isnull(txtForeName) then
' warn the user
msgbox "you have to fill in the forname, too!"
' etc etc


Depending on your circumstances, you may think of ways to streamline
this. Don't use the control's BeforeUpdate because it won't fire if the
user has not changed it.

Another approach is to avoid the situation altogether. If the field
really is mandatory, you might want to put a DefaultValue in the table
description. If you then end up with a lot of clients called
"DefaultForename DefaultLastName" then you know you have a user training
issue to deal with. Alternatively, you could demand a Name before letting
the user attempt to create a new record -- use the Form_Load event for
this. If there are genuine times when a person's name is unknown, then
you may be better off removing the Required attribute altogether. I am
generally suspicious of required fields that don't have obvious default
values too.

Hope that helps


Tim F
 
J

Jim Normile

Thanks Allen......simple but clear

Jim

Allen Browne said:
A simple way to do this is to set the Required property of the field in the
table to No.

Instead, set the Validation Rule to:
Is Not Null
and you can then set the Validation Text to whatever you want.

To trap the error at the form level instead, use the Error event of the
form. Set up your own error message, and set the Response argument to
acDataErrContinue.
 

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