Rick said:
Only if you ALWAYS update using a form and have code in the form apply the date.
You cannot define this at the table level in a Jet (mdb) table.
I'm glad you agree such metadata requirements should be implemented at
the engine level if possible. And you will no doubt be glad when I tell
you how that can be achieved <g> ...
Authorized users may not always use your form to connect to
the database (e.g. Excel, VBA, etc) so implementing the 'timestamp'
mechanism in only one front end application is unsafe (especially if
this is for audit purposes).
Consider a simplified example. Say you wanted to maintain a 'date
inserted' column for a table:
CREATE TABLE MyTable (
key_col INTEGER NOT NULL UNIQUE,
data_col INTEGER NOT NULL,
effective_date DATETIME DEFAULT NOW() NOT NULL
);
Obviously you don't want the effective_date column to be written to
directly e.g. a user could accidentally (or otherwise) enter a far
future date; let's also say this metadata need not be exposed either,
so you wrap it in a view/query:
CREATE VIEW MyFakedTable
AS
SELECT key_col, data_col
FROM MyTable;
Revoke all permissions from the table and grant them to the view/query.
Users can now insert into the view/query and the default 'timestamp'
gets automatically applied:
INSERT INTO MyFakedTable (key_col, data_col) VALUES (1, 1);
Of course, you are more likely to want a 'last modified' date i.e. the
effective_date column is additionally maintained for updates. For
Access, a stored proc/parameterized query is required e.g.
CREATE PROCEDURE SetMyTableData (
arg_key_col INTEGER,
arg_data_col INTEGER
) AS
UPDATE MyTable
SET data_col = arg_data_col,
effective_date = NOW()
WHERE key_col = arg_key_col;
Obviously you would now revoke update permissions from the view/query.
Jamie.
--