Form Controls: Enable and SetFocus Issues...

Aid2Kids

New Member
Joined
Oct 27, 2017
Messages
9
Excel 2010
Win 8 Pro

Greetings to all,

I am including some stripped-down, simplified code that illustrates a problem that I'm having with a form. This little form contains only a checkbox and 3 textboxes, with the checkbox having TabIndex 0, and the first, second and third textboxes having TabIndexes of 1,2,and 3, respectively. Here's what I want the form to do...

1) form initialization enables ONLY the checkbox; all 3 textboxes are DISabled.
2) once the checkbox is checked, the first textbox is enabled and given the focus.
3) once data is input into the first textbox and [Enter] (or [Tab]) is pressed, the second textbox is enabled and given the focus.
4) once data is input into the second textbox and [Enter] (or [Tab]) is pressed, the third textbox is enabled and given the focus.

Everything's fine until step 3: the first time [Enter] is pressed the data in the first textbox gets highlighted (why?), and then only after [Enter] is pressed a second time does the focus move to the second textbox.

Further, after data is entered into the second textbox and [Enter] is pressed, the data in the first textbox gets highlighted (why?); after [Enter] is pressed a second time the focus then moves back to the second textbox, and only after entering [Enter] a third time does the cursor finally move to the third textbox.

I'm obviously missing something here in my understanding of form events. Would someone please point me in the right direction?


THANKS!


-------------------------------------------------------------------
Code:
Private Sub UserForm_Initialize()
    Me.chkCheckBox.Enabled = True
    Me.txtBox1.Enabled = False
    Me.txtBox2.Enabled = False
    Me.txtBox3.Enabled = False
End Sub

Private Sub chkCheckBox_Click()
    Me.txtBox1.Enabled = True
    Me.txtBox1.SetFocus
End Sub

Private Sub txtBox1_AfterUpdate()
    Me.txtBox2.Enabled = True
    Me.txtBox2.SetFocus
End Sub

Private Sub txtBox2_AfterUpdate()
    Me.txtBox3.Enabled = True
    Me.txtBox3.SetFocus
End Sub
 
Last edited by a moderator:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Have you tried putting breakpoints in the code and stepping through to check in which order things are happening?
 
Upvote 0
Thank you for your prompt reply!

I'm not trying to be snarky, but I thought my original statement concerning the tab order would have answered your reply: "This little form contains only a checkbox and 3 textboxes, with the checkbox having TabIndex 0, and the first, second and third textboxes having TabIndexes of 1,2,and 3, respectively." Further, all controls have their TabStops set to True. Am I misunderstanding you?
 
Upvote 0
Thanks Norie for your prompt reply!

Yes I have used breakpoints, but I don't see where that's doing me any good in this particular case; it seems to me the issue here is what is Excel doing behind the scenes. Simply using breakpoints and single stepping through the code doesn't reveal to me the cause of this behavior.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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