PDA

View Full Version : [SOLVED] SetFocus on TextBoxes



jkaufman
09-18-2013, 10:36 AM
I am attempting to walk a user through a userform by controling how the data entry. When the Userform is first activated the user is allowed to enter information in a textbox - once the information is entered the next textbox is enabled - the label highlighted - and I attempt to put the cursor in that textbox with the Setfocus property.

When I step through the code - the cursor does go to the proper textbox but then vanishes immediately. See my code below.

Can someone help me with what I am not doing correctly? Thanks.


Private Sub TextBox2_AfterUpdate()
Label2.ForeColor = vbBlack
Label3.Enabled = True
TextBox3.Enabled = True
Label3.ForeColor = vbRed
TextBox3.SetFocus
End Sub

jkaufman
09-18-2013, 10:52 AM
Apparently I have created a "cross" thread which is a no-no.... just not getting a response and thought I would try this forum as well. Not sure how to link the two posts.

SamT
09-18-2013, 07:53 PM
Per the Cross posting, post the address of this thread in the other site's thread and that thread's address in this thread.

The reason you are not getting any responses might be because you are going against every precept of good GUI design principles.

Per your question:

Use the controls' TabIndex Property to set the order in which the focus moves to. IOW, The TabIndex of the first control the user should be in is = 1. The TabIndex of the next control to get the focus is 2, the next = 3.

You can see all the Properties of the controls in the Properties Window (Press F4)

Aflatoon
09-19-2013, 01:13 AM
Your issue is one of timing. The afterupdate event is triggered when the control is about to lose focus and before the next control gets the focus. So your code changes the focus to the specified control but then, once the code finishes, the focus moves to the control which was originally next in the tab sequence.