How do I get ACCESS to put a DAT/TIME stamp on each record?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Time Reaper
    New Member
    • Aug 2010
    • 6

    How do I get ACCESS to put a DAT/TIME stamp on each record?

    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?
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    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

    Comment

    • liimra
      New Member
      • Aug 2010
      • 119

      #3
      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,
      Ali

      Comment

      • liimra
        New Member
        • Aug 2010
        • 119

        #4
        Ops!

        Missed the part you might need them both in one field. If this is the case, just follow the same steps and use as SmileyOne stated Now() in the expression field.

        VB:
        Code:
        FieldName = Now()
        Regards,
        Ali

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          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

          • Time Reaper
            New Member
            • Aug 2010
            • 6

            #6
            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

            • Time Reaper
              New Member
              • Aug 2010
              • 6

              #7
              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

              • Time Reaper
                New Member
                • Aug 2010
                • 6

                #8
                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

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32661

                  #9
                  A novice with good manners (responding to each poster who's contributed). Sounds good to me :)

                  Let us know if you run into any difficulties and we'll do what we can to help.

                  Welcome to Bytes!

                  Comment

                  • Time Reaper
                    New Member
                    • Aug 2010
                    • 6

                    #10
                    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

                    • liimra
                      New Member
                      • Aug 2010
                      • 119

                      #11
                      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,
                      Ali

                      Comment

                      • Time Reaper
                        New Member
                        • Aug 2010
                        • 6

                        #12
                        Ali,
                        THANKS! I got it and things are working the way I'd like. Thanks again for your assistance!

                        Comment

                        • liimra
                          New Member
                          • Aug 2010
                          • 119

                          #13
                          Welcome

                          Glad you got it working the way you want.

                          Regards,
                          Ali

                          Comment

                          Working...