Consulting

Results 1 to 4 of 4

Thread: SetFocus on TextBoxes

  1. #1
    VBAX Regular
    Joined
    Oct 2011
    Posts
    11
    Location

    SetFocus on TextBoxes

    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

  2. #2
    VBAX Regular
    Joined
    Oct 2011
    Posts
    11
    Location
    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.

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    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.
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •