jmonty said:
If you are saving this in a table field:
Go into table design and select the field. (It must be set to type:=
Date/Time)
Enter Now() or Date() in the Default Value.
If you are using a data entry form:
Open it in design mode. Right click on the field and select properties.
On the Data tab..
Enter Now() or Date() in the Default Value.
And what if they are not e.g. the users has permissions to connect via
Excel, VBA, etc?
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.
--