-
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.
-
[VBA]Me.TextBox1.SetFocus[/VBA]
This should work fine. Did you put the code on the UserForm Initialize Sub?
-
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
-
I did try your solution but to no avail. Thank you anyway.
-
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.
-
What about using the tab order?
You can access that by right clicking on the form while in Design mode.
-
I have it set to tab index "0" already. Thank you.
-
Done. It still does not work. Do I need anything else in the sub with it?
-
Can you post an attachment of what you are doing?
-
Glenn
I edited my post, did you try using the Tab Order suggestion?
-
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
-
Glenn
I never posted any code.
-
Yes. I had the textbox set to TabOrder "0". Thanks.
-
Glenn
There isn't a TabOrder property.
I mean right click on the form in Design mode and then select Tab Order.
-
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
-
I did that already. When I click on the tesxtbox and look at the taborder, it is zero.
Thanks
Glenn
-
[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]
-
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.
-
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
-
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
-
Forum Rules