Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 27

Thread: Solved: Placing cursor in a specific textbox when form opens

  1. #1
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location

    Question Solved: Placing cursor in a specific textbox when form opens

    Hi All.

    I simply want to ensure that a particular textbox has the focus and the cursor when a small pop-up VBA userform opens. I have tried to use PartNumberBox.setfocus but it doesn't seem to work. ("PartNumberBox" is the real name of the text box)
    I have also tried some other items I found in other websites to no avail.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    [VBA]Me.TextBox1.SetFocus[/VBA]

    This should work fine. Did you put the code on the UserForm Initialize Sub?

  3. #3
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    I placed PartNumberBox.SetFocus immediately after the form.show command. This was in the first sub called from the main routine.

    Do I need to use the "me." ?

    Regards,

    Glenn

  4. #4
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    I did try your solution but to no avail. Thank you anyway.

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You need to put it in the Initialize Sub for the UserForm. Go to the UserForm code and select UserForm from the left drop-down and Initialize from the right. Put the code in that macro.

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    What about using the tab order?

    You can access that by right clicking on the form while in Design mode.

  7. #7
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    I have it set to tab index "0" already. Thank you.

  8. #8
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    Done. It still does not work. Do I need anything else in the sub with it?

  9. #9
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Can you post an attachment of what you are doing?

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Glenn

    I edited my post, did you try using the Tab Order suggestion?

  11. #11
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    Hi. I created the following sub:

    [VBA] Private Sub UserForm_Initialize()

    OpDataEntryForm1.PartNumberBox.SelStart = 0
    OpDataEntryForm1.PartNumberBox.SelLength = 0
    OpDataEntryForm1.PartNumberBox.SetFocus

    End Sub
    [/VBA]
    Any other ideas?

    Regards,
    Glenn

  12. #12
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Glenn

    I never posted any code.

  13. #13
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    Yes. I had the textbox set to TabOrder "0". Thanks.

  14. #14
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Glenn

    There isn't a TabOrder property.

    I mean right click on the form in Design mode and then select Tab Order.

  15. #15
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    Hi. Jake. I posted the sub in another reply. Further information: I do not show the form until I qualify an input bit and a static variable. I then clear the text boxes and show the form. I have to sign off from my desktop and sign in on my actual development system. I will be back shortly

    Thank you,

    Glenn

  16. #16
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    I did that already. When I click on the tesxtbox and look at the taborder, it is zero.

    Thanks

    Glenn

  17. #17
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    [VBA] Public Sub OpDataEntry1()

    Dim LoadOcyd1 As Integer
    Dim testcell As Variant 'Test for bad data in spreadsheet cells

    testcell = Worksheets("Operator").Range("BR14") 'ILoad station #1 Sensor
    If CStr(testcell) = "Error 2042" Then 'Com Error
    Exit Sub
    ElseIf CStr(testcell) = "Error 2023" Then 'Application Error
    Exit Sub
    End If

    LoadOcyd1 = Worksheets("Operator").Range("BR14") 'Load station #1 Sensor

    If LoadOcyd1 = 0 Then 'When the Load Station sensor goes off, cancel keep

    test1 = 0 'Clear the bit declaring that the pop-up already displayed

    OpDataEntryForm1.Hide

    Exit Sub

    End If

    If test1 = 1 Then

    Exit Sub

    End If

    If LoadOcyd1 = 1 Then

    If ReuseData1 = False Then

    PartNumberBox.Value = ""
    PnValid1 = False

    NumberOfPanels.Value = ""
    NumPnls1 = False

    OpInitials.Value = ""
    Initials1 = False

    CommentBox.Value = ""

    SendToPLC.Enabled = False

    End If

    If ReuseData1 = True Then ' Copy saved values to the load station

    Worksheets("Operator").Range("AA16") = Worksheets("Operator").Range("T16")
    Worksheets("Operator").Range("AB16") = Worksheets("Operator").Range("U16")
    Worksheets("Operator").Range("AC16") = Worksheets("Operator").Range("V16")
    Worksheets("Operator").Range("AD16") = Worksheets("Operator").Range("W16")

    SendToPLC.Enabled = True

    End If

    End If

    OpDataEntryForm1.Show

    test1 = 1 'This tells us that the form was already revealed for this load

    'PartNumberBox.SelStart = 0
    'PartNumberBox.SelLength = 0
    'Me.PartNumberBox.SetFocus

    End Sub
    Private Sub UserForm_Initialize()

    OpDataEntryForm1.PartNumberBox.SelStart = 0
    OpDataEntryForm1.PartNumberBox.SelLength = 0
    OpDataEntryForm1.PartNumberBox.SetFocus

    End Sub
    [/VBA]

  18. #18
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Glenn

    Maybe I'm missing something but as far as I know a textbox doesn't have a TabOrder property.

    Try right clicking on the form not the textbox.

    You should then get an option Tab Order.

    And when you select that you should be able to change the tab order of all the controls on the userform.

  19. #19
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    Thank you for showing me that feature. I did the right-click and selected tab order. It IS in the correct order with the textbox I wanted at the top of the list.

    Thank you.

    What I was saying was clicking on the textbox and looking at the properties, there is a "TabIndex" property, which I set to "0". I checked all of the textboxes (4) and they are all in the correct order.

    Glenn

  20. #20
    VBAX Regular
    Joined
    Jun 2005
    Posts
    15
    Location
    I did NOT yet solve this, but I will try something else. Thank you to both people that tried to help.

    Regards,

    Glenn

Posting Permissions

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