UserForm Textbox.setfocus help

J

JMay

The following code is not consistent; The focus is set ONLY the FIRST TIME I
activate the Worksheet - If I lease WS (Deactivate - UserForm1.hide) and
return to WS (Below) my textbox1 DOES NOT GET THE FOCUS.. What am I missing?

Private Sub Worksheet_Activate()
With UserForm1
.TextBox1.Value = ""
.TextBox2.Value = ""
.TextBox3.Value = ""
.Show vbModeless
.TextBox1.SetFocus ' This line not being consistent
End With
End Sub
 
J

JLGWhiz

If you hide the form, it is still active. So when you unhide it the Activate
event is not triggered and your macro does not run. To remedy this, add a
line after your unhide command line to again set focus.

UserForm1.Show
UserForm1.TextBox1.SetFocus
 
J

JLGWhiz

After some experimenting, it looks like the problem is in the Show.Modeless
command. It seems that when it shows modeless that there is no focus set
until the form is clicked. However, when it is shown modal, the default
focus goes to the first control in the pecking order on the form.
Apparently, this is a design characteristic.
 
J

JMay

Thanks JLG;
So I could leave the Userform Modeless
I added a Close UserForm Button (which Hides it only)
When I reactivate my Sheet (with the UF) the
Textbox1 gets focus (EVERY TIME).

Thanks for hanging in there and providing the help..

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top