Results 1 to 9 of 9
  1. #1
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476

    'LastUpdated' fiedld be automatically updated


    Sorry, my title might be confusing with my question/thread. I believe to have posed this question once before, but was unsuccessful so want to revisit my query. With my Dealership database I have a Table & a Form with ALL of the Vehicle’s information. For now let’s focus on these fields, ‘DatePurchased’ & ‘SaleDate.” I have a field called, “LastUpdated” in which whenever I make any changes in a “Record” I manually tab over to the ‘LastUpdated’ field & change it to the current/today’s date. Is there any way that when I make any changes in any of a Record’s fields the ‘LastUpdated’ field automatically changes to the current/today’s date?
    If this involves VBA Coding or using Macros I will need extensive help in writing them.
    Thanks in Advance

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Actually the code is very simple. On your form, add a control that is tied to the LastUpdated field. The name of the control should default to the name of the field. You can set the control's visible property to No so that your users do not see the the last updated date (and thus cannot change it). Now in the form's Before Update event, add the following code:

    Me.LastUpdated = Now()

    The me. is just a shorthand for the current form. The LastUpdated is the name of the control (which happens to be the same name as the field in the underlying table); of course, you can always give the control a name that is different from the field name.

  3. #3
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    jzwp11, Thanks for responding to my thread. I knew that it was too good to be true. I followed your instructions, but the Date doesn't change when either I Click into a new record or hit the Refreash Button. One thing that confuses me, why is it a Before Update event rather than an After Update event?

  4. #4
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Wait, pardon me. you said add a "Control" what type of "Control" do I add?

  5. #5
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You will want to add a textbox control to your form. That control needs to be tied to your lastupdated field (i.e. the control source must be the lastupdated field). I changed the visible property of that control to No to make it hidden. I played around with the form's after update event but it did not act as I thought it would so I opted for the before update event instead.

    For an existing record, you have to change something for the before update event to be triggered, just clicking in a control will not do it. For new records, you have to complete the entry of the record.

  6. #6
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Yea, I added a text box, named it "LastUpdated," put in the Code in the Before Update event. Saved, closed, & opened up the Form, made a change in one of the Records, clicked into another Record & "LastUpdated" date didn't change. No luck...

  7. #7
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Did you put the code in the before update event of the text box or the before update event of the form? It has to be in the before update event of the form.

  8. #8
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Hey, I got it! Now I need to write down all of the steps for future reference. Thanks a lot!!!!!

  9. #9
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome. Glad you got it working.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-11-2012, 02:57 PM
  2. SellRate should get updated
    By jalal in forum Access
    Replies: 6
    Last Post: 08-10-2012, 07:36 AM
  3. autofill box is always updated as 0.
    By mejia.j88 in forum Forms
    Replies: 7
    Last Post: 11-08-2011, 07:15 PM
  4. records with different updated report_date
    By lizzywu in forum Reports
    Replies: 3
    Last Post: 10-27-2011, 01:28 PM
  5. Append only updated records
    By Fabdav in forum Queries
    Replies: 4
    Last Post: 10-10-2011, 11:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums