Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Current Date with a Button

Form Basics

Add Current Date with a Button

by  Garridon  Posted    (Edited  )
You can add a button to your form that, when clicked will add the current date for your user to a field.

Create a button and call it cmdAddDate. Insert the code below into the On Click event procedure of the button. The field txtCompleted refers to the field you want to insert the date into.

Private Sub cmdAddDate_Click()
On Error GoTo ErrorAddDate

Me.txtCompleted = Date

ExitAddDate:
Exit Sub

ErrorAddDate:
MsgBox Error.Description
Resume ExitAddDate
End Sub

For date and time, use the following code. Make sure you change the field's Format properties to General Date.

Private Sub cmdAddDate_Click()
On Error GoTo ErrorAddDate

Me.txtCompleted = Now()

ExitAddDate:
Exit Sub

ErrorAddDate:
MsgBox Error.Description
Resume ExitAddDate
End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top