Insert date and time with button

spectraflame

Well-known Member
Joined
Dec 18, 2002
Messages
830
Office Version
  1. 365
Platform
  1. Windows
I have the following code set up to run on the on click event.

Private Sub CloseWOButton_Click()
Me.Status = "Closed"
Me.ClosedBy = Environ("Username")
Me.ClosedByDate = Now()
End Sub

The first 2 statements work correctly, but the last one to insert the current date and time errors out. The ClosedByDate text box is formatted as General Date.

Is there a better way to insert the current date and time from a button and store the result in field on the form as well as in the table?

Matthew
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Worked for me when I tried it.
Check the data type of the ClosedByDate field (in the table), to make sure it's Date/Time. Alternatively, look for a typo in the name and/or check that the text box's name matches the one in the code.

Denis
 
Upvote 0
Thanks,

Thanks for reminding me to check my spelling. That was the problem. I spent 3 hours looking for it and not thinking of the obvious first.

Thanks again,
Matthew
 
Upvote 0

Forum statistics

Threads
1,221,893
Messages
6,162,659
Members
451,780
Latest member
Blake86

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