Insert the current date and time with the default value field property In this Microsoft Access video tutorial, you will learn how to use the Default Value property in your tables to automatically insert the current date and time into new records. This is great for work logs, order entry, or anything else that requires a date/time stamp. You can learn more about the Default Value property,
and many of the other table field properties in my Access 2010 Beginner Level 3 Tutorial.
Take, for example, a simple table with three fields: an ID (AutoNumber), a DateTime field (Date/Time data type), and a Description field (Text). As you enter records into the table, you are forced to manually type in the current date and time for each record. This can be quite laborious, even with the Date Picker button, because you still have to type in the time. It would be nice if there was a way for Access to automatically insert the current date and time for you. Open your table in Design View. Click on the DateTime field and notice the list of field properties at the bottom of the window. Find the Default Value property. The Default Value is the value that a new record starts out with. You can change it if you want, but Access will create new records with this value. You can set the Default Value to a static value. For example, if most of your customers are from New York, you could set the Default Value for a State field to �NY�. In this case, we want the current date and time to be inserted. In order to have a Default Value that inserts the current date, type the following into the Default Value property: Date() This is the Date Function. Notice the empty parentheses. This indicates to Access that you�re dealing with the Date Function, and not just the word �Date.� The Date Function returns the current date and places it in this field. Since Date() doesn�t return the time, we�ll get today�s date at midnight. If you save the table and switch over to Datasheet View, you�ll see that the next new record will be created with today�s date. Now, we want the current date with the current time. So instead of Date() type in: Now() The
Now Function returns the current date along with the current time. This will allow you to create a date/time stamp for your record. Each time you enter a new record, the date and time are inserted automatically for you.
By Richard Rost Click here to sign up for more FREE tips |
Check out these other pages that may be of interest to you: |
The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
10.11.12.13.14.15.Delete the NEWDEPARTMENTS table.Home>Records groups>Delete (Yes) to NEWDEPARTMENTSCreate a backup of the database. You do not need to change the backuplocation.From the current view, rename the ID field to: DEGREENAMEFrom the current view, add a new Short Text field to the far right side of thetable. Name the field : DESCRIPTIONAdd theSTATUSquickstartfield to the right of the DegreeName field.From the current view,deletetheDescriptionField.16. Use theEnterFieldPropertiesdialog torenamethe ID field toDEGREENAMEand change the caption to DEGREENAME. Do not add adescription.