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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,836
Office Version
  1. 2010
Platform
  1. Windows
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

rs2k

Well-known Member
Joined
Aug 15, 2004
Messages
1,413
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

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,836
Office Version
  1. 2010
Platform
  1. Windows
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

rs2k

Well-known Member
Joined
Aug 15, 2004
Messages
1,413
No worries, anybody else?
 
Upvote 0

BrianWren

New Member
Joined
Sep 8, 2014
Messages
5
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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,190,896
Messages
5,983,437
Members
439,843
Latest member
PlanetFitness

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
Top