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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,216,111
Messages
6,128,899
Members
449,477
Latest member
panjongshing

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