I am creating a very simple database using barcode readers to input an ID number and location. I want ACCESS to automatically populate a date/time field with a date/time stamp to record when the record was created. How would I achieve this?
How do I get ACCESS to put a DAT/TIME stamp on each record?
Collapse
X
-
Tags: None
-
As far as I know, Access has no built-in support for this. If you only need to keep time of when its created, its rather simple.
Add a field to your table, dt_Created, make it date/time type, in the default value, write "=NOW()" or "Now()" (I can't remember if the "=" is required)
Hope that works for you, if you have more questions come again!
Welcome to BYTES -
Solution/
The table which will save your records should have two additional fields "Date" & "Time" (choose different names as these are reserved Access names).
Now create a form based on the table. Open it in design view and Append a macro to the On Load Event (--> Property Sheet --> Even ---> on Load). Use the "SetValue" Action (you must show all macro actions to see this one). Now type the name of the date field on the form and "Date()" as the expression. If the field is called DateA, then
Item: [Date]
Expression: Date()
For the time field, suppose the name of the field is TimeA, then
Item: [TimeA]
Expression: Time ().
Of course you can attach this macro to any other event like after updating one field ...etc.
Alternatively you can use VB, again attach this code to the event you desire, on load, focus on a field,...etc
Code:DateA = Date TimeA = Time()
Regards,
AliComment
-
A .DefaultValue of Now() is a pretty decent approach, but it does suffer from inaccuracy if the record isn't saved immediately the new record is navigated to. Depending on how important precise accuracy is in all cases (generally not too important and this could easily be considered adequate in many scenarios) you may prefer to handle the BeforeInsert event by setting the value of the control to Now().Comment
-
SmileyOne,
Thanks for taking the time to respond. Your suggestion is actually the first thing I did and this doesn't work the way I want it to. NeoPa describes the issue I have. I need the date/time stamp to record when the data is input, not when the record is created. Since a new record is created after the completion of the previous record, the date/time stamp is inaccurate.
Oh... did I mention I'm a novice? But you already knew that by my post. ha!
Thanks again!Comment
-
Ali,
Thanks for taking the time to respond. Good suggestions and I'll get cracking on them. I'll post my results when I can.
Thanks again!Comment
-
NeoPa,
Thanks for taking the time to respond. Your assessment is right on. I'll work on all the suggestions given to me and post the results.
Thanks again!Comment
-
Ali,
So I get all the way to the point I'm at the pull-down menu under "Action" per your recommendation. However, "SetValue" is not listed in my menu. Why would this be?
yeah... have I mentioned I'm a novice....Comment
-
You are welcome.
When you have it opened, look at the ribbon --> you will see "Show All Actions" --> Make sure it is selected, then you will be able to select the set value action.
Note, that you can attach this macro to any event. For example, if you want the date & time to be inserted after you select the ID field, you use the "On Focus event" after selecting the field and so on.
Hope this helps,
Regards,
AliComment
-
Ali,
THANKS! I got it and things are working the way I'd like. Thanks again for your assistance!Comment
Comment