working hotkey even if any control has focus in userform

X

x taol

i want to close the userform if press the esc key.
Current, the userform have many controls.

in that case, even if any control has focus, i want to close the
userform when the esc key pressed.
 
B

Bob Phillips

Add a button to the form, and code like so

Private cmdEsc_Click()
Unload Me
End Sub

and set the Cancel property of that button to True

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
X

x taol

thanks bob.
then, I will automate your source code.

Private cmdEsc_Click()
Unload Me
End Sub

my source code follow.
with me.controls.add("forms.commandbutton.1")
Left = 10
Top = 10
Width = 0
Height = 0
Cancel = True
End With
and then i don't know
 
B

Bob Phillips

Don't add the button dynamically, add it at design.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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