cursor not starting in textbox

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have a userform with a textbox1 on it. and when the userform launches I would like to have the cursor already in it. This textbox is in the number 1 position on the tab order, and I have set the focus on it when the form launches but I still have to click inside the textbox to get the cursor in it to enter data. Can anyone offer any input on why the code isn't putting the cursor in to the textbox?

Thanks,

(I am using a QR scanner to enter the data so that it why I dont want to have to manually click in the text box, I want the cursor already there)


Code:
Private Sub UserForm_Initialize()
    Dim i As Long
    Dim Lastrow As Long
   
    
    TextBox1.SetFocus
    
 'this is from the DEVICE ID column
    Lastrow = Cells(Rows.Count, "L").End(xlUp).Row
         For i = 1 To Lastrow
             If Cells(i, 15).Value = "" Then ListBox1.AddItem Cells(i, 12).Value
         Next
         Me.RemainingCountBox.Text = CStr(ThisWorkbook.Sheets("Emergency Lighting Log").Range("M1").Value)
      
         
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Please check property of the Textbox, and chenge the TabIndex be "0".
 
Upvote 0
Hi Takae - thanks for responding, yes it already is at "0". That's why I am still scratching me head. So this is the correct syntax right? Maybe I should have asked that question first - lol

The sub that runs directly after this "cycles" through the form. The user enters data, and the sub sends it to the worksheet and then just clears out the textboxes without closing it so the user can enter in more data. The interesting thing is that textbox1 gets its cursor when the it is recycled, but not when it is initially started. Using the same code syntax for both, so it must have something to do with the intialize event. That being said I really didn't think I needed it because textbox1 is the first item in the tab order; but i thought if I added the setfocus it would force it to do it. I can't see on the userform what object is getting the initial focus instead...
 
Upvote 0
Did you hide the UserForm?
I am not sure...
UserForm1.Show---("Initialize" runs)---Hide the UserForm----Show UserForm---("Initialize" does not run but "Activate" runs)
 
Upvote 0
Hi Takae, I have tried a couple of different things, even tried putting it in the sub that calls this sub but that returned an object error - no surprise there. This isn't a deal breaker, just one of those little quirks - the user will just have to click in the box one time. so I think I will just put this to bed for now, maybe someday I will run across something that will resolve this. Thanks for your assistance, it is appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top