access forms Constraints on fields

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

Guest

How do I Make fields or a field able to be left Null or required based on a
prior fields combobox value or a check box selection. For example , if
textbox field Married = yes, then (textbox's, fields) spouse name , date of
birth fields must have values entered , if Married =NO then the fields can be
left null or blank and user can submit form.
 
Try this in Form's BeforeUpdate

If me.married = "yes" then
if isnull(me.SpouseName) then
msgbox "You must enter a spouse name."
me.SpouseName.setfocus
elseif isnull(me.DOB) then
msgbox "You must enter the Date of Birth."
me.DOB.setfocus
end if
Elseif me.married = "no" then
if not isnull(me.SpouseName) then
msgbox "Delete the spouse name." or whatever you want to do
me.SpouseName.setfocus
elseif not isnull(me.DOB) then
msgbox "Delete the Date of Birth." or whatever you want to do
me.DOB.setfocus
end if
End If

HTH,
Debbie


| How do I Make fields or a field able to be left Null or required based on
a
| prior fields combobox value or a check box selection. For example , if
| textbox field Married = yes, then (textbox's, fields) spouse name , date
of
| birth fields must have values entered , if Married =NO then the fields can
be
| left null or blank and user can submit form.
 
Thank you , this worked well! I have another question if you could help me
out. I have a Date field and i would like this field to function the same
way, ie.. If a date value has been entered then the next 5 fields must be
completed. Since the date can be a random date and it is not a typical "yes"
or "no" parameter from a combo box, how would i flag the next fields to
require a value if TextboxDate= a value
 
Glad that worked. Someone else may come up with something more elegant but

if not isnull(me.TextboxDate) then
if isnull(me.TheFirstField) then
msgbox "You must enter a ..."
me.TheFirstField.setfocus
elseif isnull(me.TheSecondField) then
...
end if
end if

HTH,
Debbie


| Thank you , this worked well! I have another question if you could help me
| out. I have a Date field and i would like this field to function the same
| way, ie.. If a date value has been entered then the next 5 fields must be
| completed. Since the date can be a random date and it is not a typical
"yes"
| or "no" parameter from a combo box, how would i flag the next fields to
| require a value if TextboxDate= a value
|
| "DebbieG" wrote:
|
| > Try this in Form's BeforeUpdate
| >
| > If me.married = "yes" then
| > if isnull(me.SpouseName) then
| > msgbox "You must enter a spouse name."
| > me.SpouseName.setfocus
| > elseif isnull(me.DOB) then
| > msgbox "You must enter the Date of Birth."
| > me.DOB.setfocus
| > end if
| > Elseif me.married = "no" then
| > if not isnull(me.SpouseName) then
| > msgbox "Delete the spouse name." or whatever you want to do
| > me.SpouseName.setfocus
| > elseif not isnull(me.DOB) then
| > msgbox "Delete the Date of Birth." or whatever you want to do
| > me.DOB.setfocus
| > end if
| > End If
| >
| > HTH,
| > Debbie
| >
| >
| > | > | How do I Make fields or a field able to be left Null or required based
on
| > a
| > | prior fields combobox value or a check box selection. For example , if
| > | textbox field Married = yes, then (textbox's, fields) spouse name ,
date
| > of
| > | birth fields must have values entered , if Married =NO then the fields
can
| > be
| > | left null or blank and user can submit form.
| >
| >
 
Back
Top