Textbox to take focus

  • Thread starter Thread starter Arkimediz
  • Start date Start date
A

Arkimediz

I have command button that makes a text box visible to
input a password. How do I make the text box take the
focus to input the password without having to click in it
and can I make the enter key take the action to check the
password instead of having to use another command button?
 
assuming you are using a userform, set the taborder to 0 for the textbox.

use one of the key events to detect the enter key.
 
for the commandbutton you need something like this

Private Sub CommandButton1_Click()
TextBox1.Visible = True
TextBox1.SetFocus '
End Sub




for the textbox use the Keydown event. something like this.

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 13 Then


'your ACtion here


End If

End Sub




Cesar Zapata
 
Not using userform but just a textbox and I am not sure
how to use the key events. Sorry.
 
Activesheet.Textbox1.Activate


Private Sub TextBox1_KeyUp(ByVal KeyCode As _
MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
' code to validate entry
End If
End Sub
 
Based on Arkimediz latest input, it appears the textbox is not on a
userform.
So just for information for Arkimediz, a textbox on a worksheet does not
have a setfocus method.
 
Thank you - first bit works to "take focus"

Will work on next bit!!
 
If you put the KeyUp event in the same module as the CommandButton event,
then it should work. It worked for me. (unless you mean add the code to
validate the password).
 

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

Back
Top