VBA Add a Change Date

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,340
Office Version
  1. 365
Platform
  1. Windows
On a form I have two fields (From a Table). One is a Comments field (Long Text) and the other is a Date Field

I need an Event that whenever the Comments field is changed the Date field ("Status_Comments_Date") is changed to the current date.

Help please.

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Assuming your field names are "Comments" and "Status_Comments_Date".
Go to the Comments field on your form, bring up Properties, go to the Event tab, and select the Code Builder option and add this VBA code:
Code:
Private Sub Comments_AfterUpdate()
'   Update Status_Comments_Date field to current date whenever Comments field is updated
    Me.Status_Comments_Date = Date
End Sub
Note that the Status_Comments_Date field must be on the Form. If you do not want it shown, just change its Visible property to "No".
 
Upvote 0
You can use NOW() instead of DATE in my code if you want to capture a time component along with the date.
 
Upvote 0
Another way would be to use the table level after update event.

If you haven't used table events before I would recommend looking into them, it means that no matter where the data is changed any form, any query or in the table itself) the event will trigger. They take a bit of getting used to, however, they are a good way to manage data integrity and audit functionality.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top