Closing Form on pressing Enter or Return-key

E

eoleo.ftp

Hallo,

in my UserForm I use a combobox that takes the focus, when the Form
opens. By using shortcut Ctl+D a dropdown is executed so the user is
able to select entries by using the arrow-keys.

Now I would like the programm to act as follows: If the user presses
the return or enter-key the form should close.
How can I reach that?

Thanks in advance.
Leo
 
D

Dave D-C

How about:
Private Sub ComboBox1_KeyDown( _
ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = 13 Then UserForm1.Hide
End Sub

Did you do your shortcut with:
Private Sub ComboBox1_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 4 Then UserForm1.ComboBox1.DropDown
End Sub ' ?
If not, how, please. Tnx D-C
 
E

eoleo.ftp

Thanks, works fine!

Leo

How about:
Private Sub ComboBox1_KeyDown( _
ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = 13 Then UserForm1.Hide
End Sub

Did you do your shortcut with:
Private Sub ComboBox1_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 4 Then UserForm1.ComboBox1.DropDown
End Sub ' ?
If not, how, please. Tnx D-C
 

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