VBA to insert current Date into field

Thebatfink

Active Member
Joined
Apr 8, 2007
Messages
410
Hi,

No doubt this is rediculously simple but I'm only just starting out with Access and finding it nothing like Excel!

I have an existing Form_Afterupdate sub that exists in a database written by someone else and I want to tag onto the end of it the inserting of the current date into a tables field for the current record.

I'm unsure of the syntax to use though! so if someone could point me in the right direction .. Also, if anyone has any good websites which deal with the basics of programming in Access like Mrexcel and Ozgrid are for Excel so I can try self teach a little it would be greatly appreciated!

Thanks!
Batfink
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you are using a form, then you could just include the field on the page hidden but populate it with a default value of Now() or Date().
 
Upvote 0
It's simpler to open the underlying table is Design mode, click on the date field, and type "Now()" in the Default Value slot. That way any new record in that table, created by whatever means, gets the date and time at the moment it's created.

Form_AfterUpdate won't work -- it's a Catch-22. You want the field populated with the current date, which should be done at Form_BeforeUpdate.
 
Upvote 0
It's simpler to open the underlying table is Design mode, click on the date field, and type "Now()" in the Default Value slot. That way any new record in that table, created by whatever means, gets the date and time at the moment it's created.
Well, sort of. It will populate the date and time when the New Record is Displayed not when it is completed. So if you have the default set to NOW() then when you just navigate to a new record it will keep that date and time, even if you don't even start the record until 2 hours later. So, the second option - using the form's BEFORE UPDATE event is the better option.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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