Question Today's date in a calculated field

I found the solution!
Open the table design view.
Click on create data macros.
Select "before change".
Enter:
===
If [IsInsert]=true Then
Setfield
Name
Planned
Value = now()
End If
===
"Planned" is of course the field where I want the timestamp.
The above text is partially generated in the process by access itself.
It works!
 
I found the solution!
Open the table design view.
Click on create data macros.
Select "before change".
Enter:
===
If [IsInsert]=true Then
Setfield
Name
Planned
Value = now()
End If
===
"Planned" is of course the field where I want the timestamp.
The above text is partially generated in the process by access itself.
It works!
Won't that set the Planned on every change to the record? I thought you only wanted to store the DateCreated?
 
Won't that set the Planned on every change to the record? I thought you only wanted to store the DateCreated?
The "IfInsert=True" clause prevents that. Without that, it is indeed changed with every update.
 
No, it doesn't, they are simply placeholders and it says <New> in the Autonumber field.

On the table go to the last record, and look at the "New" record
Press F5 to refresh the screen, it will update the Now() default value to the current time.
You are right that refreshing updates it. But that is an extra action. That I wanted to avoid, and also it is easily forgotten.
Without refreshing, the existing (old) value is fixed as soon as a value is entered somewhere in the record.
On the basis of your message I hoped that access would refresh the value automatically before fixing it, but that doesn't seem to be the case.
 
Only if you are directly entering data into the Table, which you shouldn't be doing.
If you open a form and then click on new record the Now() default value will be correct for when the new record is created.
 
Only if you are directly entering data into the Table, which you shouldn't be doing.
If you open a form and then click on new record the Now() default value will be correct for when the new record is created.
In this particular case I wanted to do it without a form. Next time that I do use a form I will try out your suggestion, because until now, in forms I used a "before update" event in the design to create a timestamp, which is much more work than what you suggest.
 
Additionally, If you insert new records with a query then the Now() default value also works for when the record is created.
 
In this particular case I wanted to do it without a form. Next time that I do use a form I will try out your suggestion, because until now, in forms I used a "before update" event in the design to create a timestamp, which is much more work than what you suggest.

1. You said you didn't want to set the time when the record was inserted and yet that is what you are doing with the data macro. Simply setting a default solves the problem. No macro is needed.
2. If one line of code is hard for you, maybe some training will help.
at 1: no, timestamp for Date Created meaning the first time any value was entered in a field was exactly what I wanted.
at 2: thank you for this welcoming comment.
 

Users who are viewing this thread

Back
Top Bottom