Check for Enter key and change focus?

N

NooK

I have a Userform which has a textbox, two Option Buttons and a Ad
button.

The user type something in the box, chooses one of the 2 choices an
press Add (To add the data to a Listbox)

Now what I need is that the user can type the number on the textbo
and press Enter to add the data to the listbox (Assuming the optio
buttons are already chosen), but neither KeyUp or KeyPress events seem
to listen to the Enter Key on the keyboard.

How can this be done?

Another question is that when the user press the add button I woul
like the cursor to go back to the textbox so that he can press Add an
right after type the new data (Without having to click on the text bo
again).

Hopefully they can be done.

Best Regards

Noo
 
N

NooK

Thanks, the SetFocus worked out nicelly, but the Exit event is not wha
I am looking for because if the user for example clicks anywhere els
in the form (Say the listbox) whatever is in the textbox wil
automatically be aded to it and that's not right, Only if the use
presses Enter is the stuff to be added.

Isn't there anyway at All?

Best Regards

Noo
 
N

NooK

Sorry for the delay on the answer, I was away on vacation with no acces
to internet.

Are you sure Keyup and Keydown are triggered by Enter because i
doesn't do it here.

I did

Private Sub tbData_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVa
Shift As Integer)
MsgBox (KeyCode)
End Sub

And when I press any button on the textbox I get a msgbox saying it'
code but when I press Enter nothing appears and the focus changes t
the next control.

Best Regards

Noo
 

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