Command Button To Enter Time

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
 
J

Joan Wild

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.)
 
A

Al Camp

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top