Click button to retrieve Now() (1 Viewer)

Zydeceltico

Registered User.
Local time
Today, 16:36
Joined
Dec 5, 2017
Messages
843
Hi All -

I have two Date/Time fields.

One is called "Start" and the other one is called "Stop."

Is there a way to convert their respective labels into a clickable control that retrieves "=Now()" and puts it in the text box as a storable value?

The idea is like a stopwatch.

Thanks in advance!

Tim
 

Attachments

  • ClickNow.zip
    23 KB · Views: 75

plog

Banishment Pending
Local time
Today, 15:36
Joined
May 11, 2011
Messages
11,611
The input itself is clickable. So the short answer is just add the code to the OnClick event of that control.

You could also add a button, lock down the field and update it whenever its corresponding button was clicked.

You could also delete the attached labels you have, add unattached labels and then use the OnClick event of those new labels as you initially described.
 

isladogs

MVP / VIP
Local time
Today, 20:36
Joined
Jan 14, 2017
Messages
18,186
I normally use one or two buttons. Several examples elsewhere in the forum including these which I've posted in sample databases Reaction Timer, Countdown Timer
 

bdra2778

Registered User.
Local time
Today, 13:36
Joined
Feb 14, 2019
Messages
34
Hello, see attached file, I hope is that you looking for
 

Attachments

  • ClickNow-bdra2778.zip
    24.4 KB · Views: 81

Zydeceltico

Registered User.
Local time
Today, 16:36
Joined
Dec 5, 2017
Messages
843
The input itself is clickable. So the short answer is just add the code to the OnClick event of that control.

You could also add a button, lock down the field and update it whenever its corresponding button was clicked.

You could also delete the attached labels you have, add unattached labels and then use the OnClick event of those new labels as you initially described.


How do I "lock down the field?"
 

Zydeceltico

Registered User.
Local time
Today, 16:36
Joined
Dec 5, 2017
Messages
843
Hello, see attached file, I hope is that you looking for

That is SUPER close to what I am looking for!

I need to see if I can modify your code a bit. The typical scenario in the shop is over minutes or even hours not seconds - - -

So I would want to literally have two buttons and two text fields instead of one button and two fields - although that is very slick.

The reason that what you have provided won't work for me - in its current state - is that I will have to leave that window for quite some time - and that will introduce issues I am sure.

What I will need to do is open the form, click a button for the Start time, POSSIBLY close the form - or let it "float", come back at a later time, find that record, reopen the form and click "Stop."

Thanks!
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:36
Joined
Feb 28, 2001
Messages
27,001
The only thing I would do is add an OnClick to the LABEL (not the text box), just to avoid accidentally tabbing there (though there should be no risk of just tabbing through.)

How precisely do you want the time, though? If accuracy to the second is OK, use Now() for the function. If not, user Timer() for the function, which gives you milliseconds since midnight of the current date.
 

Zydeceltico

Registered User.
Local time
Today, 16:36
Joined
Dec 5, 2017
Messages
843
The only thing I would do is add an OnClick to the LABEL (not the text box)

I like this idea. I'm in design view. I have the label selected but I am not offered any options on the Event tab.

What do I need to do?
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 07:36
Joined
Oct 20, 2008
Messages
512
I like this idea. I'm in design view. I have the label selected but I am not offered any options on the Event tab.

What do I need to do?

Make sure the Form properties window is open, select the Label control of concern, then select Event tab on the Form Property Window, you should see 5 events there, one of them being OnClick.
 

Zydeceltico

Registered User.
Local time
Today, 16:36
Joined
Dec 5, 2017
Messages
843
Make sure the Form properties window is open, select the Label control of concern, then select Event tab on the Form Property Window, you should see 5 events there, one of them being OnClick.

For some reason both Data and Events tabs are empty on all of my control labels. It's OK. I just deleted the labels and replaced them with buttons and a line of code and it works great.

Thank You

Tim
 

isladogs

MVP / VIP
Local time
Today, 20:36
Joined
Jan 14, 2017
Messages
18,186
Labels attached to controls such as textboxes have no events as the other control would be used for any code
Unattached (stand alone) labels have 5 events:



Its impossible to add data to any labels
 

Attachments

  • Capture.PNG
    Capture.PNG
    4.4 KB · Views: 177

essaytee

Need a good one-liner.
Local time
Tomorrow, 07:36
Joined
Oct 20, 2008
Messages
512
Labels attached to controls such as textboxes have no events as the other control would be used for any code
Unattached (stand alone) labels have 5 events:



Its impossible to add data to any labels
This is something for the memory bank. I read the OP's comment while out and was wracking my brain with what could have gone wrong.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:36
Joined
Feb 28, 2001
Messages
27,001
If you are not playing color-change games with the label when you have selected the control, you can disassociate the label from the control and then assign your events. Access will kvetch about the disassociation but it will allow it.
 

Zydeceltico

Registered User.
Local time
Today, 16:36
Joined
Dec 5, 2017
Messages
843
If you are not playing color-change games with the label when you have selected the control, you can disassociate the label from the control and then assign your events. Access will kvetch about the disassociation but it will allow it.

I ended up deleting the Labels, creating buttons and adding this code to the On_Click event of the button:

Code:
Private Sub cmdLineStopBegin_Click()
    Me.txtLineStopBegin = Now()
End Sub

Works great for what I need.
 

Users who are viewing this thread

Top Bottom