As always, Jeff, your comments are welcome.
I'm interested in your suggestion that code is more robust? That's not my
experience. I strongly prefer the engine-level rules where they are
suitable, because it takes a load off me as developer to remember to enforce
them regardless of how the data is added (e.g. action query).
So, in every database I use:
- enforced RI on most foreign keys;
- Required property of appropriate fields;
- AllowZeroLength set to No for almost all text fields;
- Field-level Validation Rules for range checking;
- Table-level Validation for comparison between fields.
The fact that there's only one table-level rule has never bothered me: you
can combine rules with AND, OR, etc, with appropriate bracketing.
Certainly, the form-level code is more powerful, and the only choice for
warnings that you allow the user to override. And I will admit to running
Form-level code for most of the cases above as well, because it seems good
practice to avoid unnecessary write-attempts. Maybe that's what you were
referring to?
Overall, though, the idea of engine-level validation for the simple and
crucial rules is very appealing.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Jeff Boyce said:
Tony (and Allen)
Pardon my intrusion...
In Access/JET, the tables have no "triggers" (unlike SQL Server). If
you'll
be using JET as your back-end for your data, you'll want to do the (more
complex) validation via the forms. It is still possible to add a
validation
rule to fields in a table, but only one, and only if it doesn't relate to
other fields. You can also set ONE table-level validation rule.
The consensus is that form-level validation testing is much more robust
when
you are using Access/JET.
--
Good luck
Jeff Boyce
<Access MVP>
TonyB said:
Hi Allen,
Thanks for the reply. I didn't explain myself clearly. I was looking for
a
general method of attaching some vba code to the field in a record so
that
when a new record is entered that this code can be run to check the data for
that field is OK Basically I am trying to customize the validation rules you
get in table design view.
Since I posted I have been searching for info about this, and I think I have
concluded this is probably not possible in a table, and that this should be
done in the form used to enter the data into the table, rather than in
the
table. Would you agree ?
Thanks
Tony
Allen Browne said:
To programatically set the Validation Rule property for a field named Email
in a table named Table1, try something like this:
Currentdb.TableDefs("Table1").Fields("Fee").ValidationRule = _
"Is Null Or ((Like ""*?@?*.?*"") And (Not Like ""*[ ,;]*""))"