Execute command in field when enter key is pressed

G

Guest

How can I get a command to execute when the enter key is pressed after
entering data?
 
C

Carl Rapson

How can I get a command to execute when the enter key is pressed after
entering data?

Handle the KeyDown event for the control, and check to see if the key
pressed was the Enter key:

If KeyCode = vbKeyReturn Then
' Execute your command here
End If

One note: the KeyDown event won't fire if you have a command button on your
form which has its Default property set to Yes. In that case, you may need
to use the KeyPress event instead.

Carl Rapson
 
G

Guest

that was exactly what i was looking for. thanks.

i had to adapt one thing

If KeyAcsii = vbKeyReturn Then
' Execute your command here
End If

where does the KeyCode come into play? is it depending on the event that you
use it in? or is it just the variable you assign in the

Private Sub myField_KeyPress(KeyAscii As Integer)

thingy?
 

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