Last focus, yes last, not LOST

rs2k

Well-known Member
Joined
Aug 15, 2004
Messages
1,413
I have built a form for time sheet entry and part of this form has a custom time-picker, the user clicks a button for the hour and then a button for the minute, this is then combined into a textbox. There are 2 buttons 'confirm' and 'cancel' when confirm is clicked I need to send the time to the last textbox (time entry) that had focus. I thought of conditional formatting the textbox where I want the time to go to, but as soon as a time is picked the focus has changed.

Is there a way around this?

Many thanks
Colin
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
In the Enter event for the textboxes of interest, you can save the control to a variable:

Code:
Dim oTB As MSForms.TextBox

Private Sub TextBox1_Enter()
    Set oTB = TextBox1
End Sub

Private Sub TextBox2_Enter()
    Set oTB = TextBox2
End Sub
 
Upvote 0
Hi shg,

Thanks for the reply, however I can't get it to work. I forgot to mention that the textboxes where the time entry goes is on a continuous subform.

I put the dim statement at the top of the continuous form,which didn't work. I then tried to reference the subform with;
Code:
Dim oTB As MSForms.Forms.EmpTimeEntry2.fsubTEMP_HOURS2.TextBox
Which also didn't work.

Can you shed any light or explain in a bit more detail how to go about this?

Cheers
Colin
 
Upvote 0
Oh, here I am lost again -- I didn't realize this was the Excess forum, which I can't even spell. Sorry for the spam.
 
Upvote 0
What if you gathered the time info in a pop-up?
You could open it with a double-click in the TBox of interest.
Upon successful time selection, fill in a global variable.
Look for an event on the TBox that fires on closing the pop-up, and use that to read the global variable's value.

I am thinkin focus might not fire, but it might. But there are additional events, I think, that might: enter, activate, etc.
 
Upvote 0
Colin

You should be able to use the same method in Access, you'll just need to change how you declare the control(s).

Try just using Object, or perhaps TextBox on it's own, MSForms.Forms.EmpTimeEntry2.fsubTEMP_HOURS2.TextBox definitely won't work.:)
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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