John said:
That would be nice if Access supported CHECK constraints, Jamie.
Sorry, we're not using SQL/Server here. This is a different program
with different syntax. Triggers would be nice too.
Man, are you in for a shock <g>. OK, deep breath...
You know the native underlying data engine to the MS Access UI is Jet?
Since Access2000, this has been Jet 4.0. Well, Jet 4.0 supports CHECK
constraints. It took until Acces2003 for the UI to catch up with the
data engine: Access2003 may be put into the ironically titled 'ANSI
mode' to allow Jet 4.0 syntax to be natively used in a SQL window. In
previous versions of MS Access, one had to use the OLE DB provider.
AFAIK, the only way to do this in the UI was to use ...
.... ADO. Yes, the dreaded word. I guess MS Access 'power' users will
always prefer DAO and I'll never know why [aside: Matt Curland accuses
DAO of tainting VBA's reputation, in Advanced VB6 p110: "Data objects,
such as DAO, provide another example of poor teardown behavior. DAO has
Close methods that must be called in the correct order, and the objects
must be released in the correct order as well (Recordset before
Database, for example). This single poor object model behavior has led
to the misconception that VB leaks memory unless you explicitly set all
the local variables to nothing at the end of a function."]. Let's face
facts: if there are some useful features that can only be accessed via
an ADO connection, surely it's not too much trouble to navigate to the
Visual Basic Editor, set a reference to ADO and type in the Immediate
Window:
CurrentProject.Connection.Execute _
"ALTER TABLE Orders ADD CONSTRAINT freight_is_positive" & _
" CHECK (Freight > 0);"
Of course, one must be aware of the features introduced five years ago
to be able to use them. I suggest this MSDN article as a starting
point:
Description of the new features that are included in Microsoft Jet 4.0
http://support.microsoft.com/default.aspx?scid=kb;en-us;275561
But don't bother looking for triggers, you won't find them <g>.
Jamie.
--