+ Reply to Thread
Results 1 to 3 of 3

Autofocus on next text box

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Posts
    164

    Autofocus on next text box

    Hi,
    I have 3 textboxes in a row.
    They each have a maximum length associated with them of 2, 1, 3 respectively.
    Is it possible to automatically switch focus to the next text box when the frist one has 2 characters? and the third one when the second has 1?


    thank sin advance,
    Matt

  2. #2
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58
    hi there,
    check payload.

    Private Sub TextBox1_Change()
        If Len(TextBox1.Text) = 2 Then set_control_focus ("TextBox2")
    End Sub
    
    Private Sub TextBox2_Change()
        If Len(TextBox2.Text) = 1 Then set_control_focus ("TextBox3")
    End Sub
    Public Sub set_control_focus(ByVal objname As String)
        On Error GoTo err
        Dim obj As OLEObject
        Set obj = Worksheets(1).OLEObjects(objname)
            obj.Activate
    err:
    End Sub
    Attached Files Attached Files
    ? ? ? I like the way how Excel can access system API. Really cool ! ? ? ?

  3. #3
    Forum Contributor
    Join Date
    03-14-2005
    Posts
    164
    thanks for that. Perfect!

    with the risk of sounding stupid, what do you mean by check payload?



    Someone I am working with wants to do this with a Word document form they are working on.
    I have used your code, but replaced Worksheets(1) with Documents(1)
    although it does not seem to work....
    any ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1