Field Validation

M

MVP - WannaB

Hello, and thank you for your time.
I am adding a new field to a table and I've been requested to ensure that it
not be left blank on the condition that another field in the same table has
been filled.
So my question is
What is the best way to enforce a rule to require that a value be entered in
a field, based on the presence of data in another field. Should this be done
at that TABLE properties OR is it better to do this using VBA on the form?
There is only one form where this data will be entered.
AND please provide an example.
THANKS AGAIN..
 
D

Dennis

In the forms before update event you can check your fields and if they do not
match your conditions set
Cancel = True
 
A

Allen Browne

If the rule is absolute (no case where you need to override it), it's best
to put the rule in the table. That way the engine always enforces the rule
(e.g. even if you run an append or update query.)

Use the rule for the table (not field), i.e. the one in the Properties box
in table design. The rule will be something like this:
([Field1] Is Null) OR ([Field2] Is Not Null)

Explanation (and examples of other rules):
http://allenbrowne.com/ValidationRule.html
 
M

MVP - WannaB

Thanks Allen, that is very helpful, but as I look at this more closely I am
finding that it is more difficult that I originally thought...
I need to apply the same condition to 2 fields, and this condition is based
on the value (data) entered in 2 other fields, all in the same table and same
record.
SOMETHING LIKE (IF FIELD1 = "BBB" AND FIELD2 = "CCC" THEN FIELD3 AND
FIELD4 CAN NOT BE NULL)
Is there a way that I can use IIF() in this validation? I can not find
anything like that in your linked site, or anywhere else... and I see
nothing about setting validation rules for more then one field in TABLE
PROPERTIES.
Is table properties validation still the right place for this or need I do
this elsewhere?
I appreciate you help

Allen Browne said:
If the rule is absolute (no case where you need to override it), it's best
to put the rule in the table. That way the engine always enforces the rule
(e.g. even if you run an append or update query.)

Use the rule for the table (not field), i.e. the one in the Properties box
in table design. The rule will be something like this:
([Field1] Is Null) OR ([Field2] Is Not Null)

Explanation (and examples of other rules):
http://allenbrowne.com/ValidationRule.html

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

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

MVP - WannaB said:
Hello, and thank you for your time.
I am adding a new field to a table and I've been requested to ensure that
it
not be left blank on the condition that another field in the same table
has
been filled.
So my question is
What is the best way to enforce a rule to require that a value be entered
in
a field, based on the presence of data in another field. Should this be
done
at that TABLE properties OR is it better to do this using VBA on the form?
There is only one form where this data will be entered.
AND please provide an example.
THANKS AGAIN..
 
A

Allen Browne

Perhaps:
([Field1] Is Null) OR ([Field2] Is Null)
OR ([Field1] <> "BBB") OR ([Field2] <> "CCC")
OR ([Field4] Is Not Null)

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

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

MVP - WannaB said:
Thanks Allen, that is very helpful, but as I look at this more closely I
am
finding that it is more difficult that I originally thought...
I need to apply the same condition to 2 fields, and this condition is
based
on the value (data) entered in 2 other fields, all in the same table and
same
record.
SOMETHING LIKE (IF FIELD1 = "BBB" AND FIELD2 = "CCC" THEN FIELD3 AND
FIELD4 CAN NOT BE NULL)
Is there a way that I can use IIF() in this validation? I can not find
anything like that in your linked site, or anywhere else... and I see
nothing about setting validation rules for more then one field in TABLE
PROPERTIES.
Is table properties validation still the right place for this or need I do
this elsewhere?
I appreciate you help

Allen Browne said:
If the rule is absolute (no case where you need to override it), it's
best
to put the rule in the table. That way the engine always enforces the
rule
(e.g. even if you run an append or update query.)

Use the rule for the table (not field), i.e. the one in the Properties
box
in table design. The rule will be something like this:
([Field1] Is Null) OR ([Field2] Is Not Null)

Explanation (and examples of other rules):
http://allenbrowne.com/ValidationRule.html

MVP - WannaB said:
Hello, and thank you for your time.
I am adding a new field to a table and I've been requested to ensure
that
it
not be left blank on the condition that another field in the same table
has
been filled.
So my question is
What is the best way to enforce a rule to require that a value be
entered
in
a field, based on the presence of data in another field. Should this
be
done
at that TABLE properties OR is it better to do this using VBA on the
form?
There is only one form where this data will be entered.
AND please provide an example.
 
M

MVP - WannaB

Are you saying to use that in the table properties validation rule?

Allen Browne said:
Perhaps:
([Field1] Is Null) OR ([Field2] Is Null)
OR ([Field1] <> "BBB") OR ([Field2] <> "CCC")
OR ([Field4] Is Not Null)

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

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

MVP - WannaB said:
Thanks Allen, that is very helpful, but as I look at this more closely I
am
finding that it is more difficult that I originally thought...
I need to apply the same condition to 2 fields, and this condition is
based
on the value (data) entered in 2 other fields, all in the same table and
same
record.
SOMETHING LIKE (IF FIELD1 = "BBB" AND FIELD2 = "CCC" THEN FIELD3 AND
FIELD4 CAN NOT BE NULL)
Is there a way that I can use IIF() in this validation? I can not find
anything like that in your linked site, or anywhere else... and I see
nothing about setting validation rules for more then one field in TABLE
PROPERTIES.
Is table properties validation still the right place for this or need I do
this elsewhere?
I appreciate you help

Allen Browne said:
If the rule is absolute (no case where you need to override it), it's
best
to put the rule in the table. That way the engine always enforces the
rule
(e.g. even if you run an append or update query.)

Use the rule for the table (not field), i.e. the one in the Properties
box
in table design. The rule will be something like this:
([Field1] Is Null) OR ([Field2] Is Not Null)

Explanation (and examples of other rules):
http://allenbrowne.com/ValidationRule.html

Hello, and thank you for your time.
I am adding a new field to a table and I've been requested to ensure
that
it
not be left blank on the condition that another field in the same table
has
been filled.
So my question is
What is the best way to enforce a rule to require that a value be
entered
in
a field, based on the presence of data in another field. Should this
be
done
at that TABLE properties OR is it better to do this using VBA on the
form?
There is only one form where this data will be entered.
AND please provide an example.
 
A

Allen Browne

MVP - WannaB said:
Are you saying to use that in the table properties validation rule?

Do you think you might try that for yourself?
(Time to move on.)
 

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