Command Button To Enter Time

  • Thread starter Thread starter Pam
  • Start date Start date
P

Pam

I'm looking for a way to be able to press a command button and the current
time be entered into a field. Example: Form that contains technician, work
codes, date, start time, stop time, and comments in datasheet view. Looking
to place "Start" and "Stop" command buttons that tech can click and the
current date fill in the start field and same for stop field. Not good with
writing code, but can copy and paste and adapt to current db.
Any help is greatly appreciated.

Thanks,
Pam
 
It's unclear whether you want the current time, or the current date, or the
current date and time.

You can either set the control's default value to Now() (for date and time)
or Date() (for date) or Time() (for just the time). However note that
whichever you choose, Access will always store a date and time in the field
(i.e. for Date it will store today's date with a time of midnight this
morning; and for Time, it will store a date of Dec 30, 1899).

You could also train them on the keyboard shortcuts
Ctrl-; to enter the date
Ctrl-: to enter the time

If you want a command button then for it's click event
Me!Start = Date()
(or Now() or Time(), depending on what you want.)
 
Pam,
I don't think there's a need for two seperate buttons...

Try using the Double-Click event of your DateTime fields (ex.
StartDateTime and StopDateTime)
The user would simply Dbl-Click on the StartDateTime field, and the
current Date & Time would be entered there. Same for the StopDateTime.

Private Sub StartDateTime_DblClick(Cancel As Integer)
StartDateTime = Now()
End Sub

If you still want buttons, the code would be the same.
 
Back
Top