A question about Userforms and tabbing

A

abxy

Hi,

ok, i'm having big problem. I'm creating a userform where the instea
of the user pressing a command button to do an opertation after they'v
put something in a textbox, all they have to do is press enter on th
keyboard and the operation will be carried out.

in the code i have attached to pressing the enter key, i have it s
that the textbox is cleared and becomes the focus again. However, i
seems that the userform is also using the 'enter' key like it normall
does as well because after performing the code attached to th
pressing the key, it will tab to the next item on the userform as if
pressed enter instead of the textbox becoming focus again like i want.

To see what was going on, i changed the code so that 'g' instead o
'enter' performed the code. when i press 'g' It carried out the cod
and the textbox was cleared and became the focus, but then the letter
was in the textbox.

It seems like the code is doing what i want, but it also presses th
key afterwards, any idea on how to fix that?

here's the basic code:

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

TextBox1.Value = ""
TextBox1.setfocus

End If

End Su
 
K

Kevin

Why not use the Exit event, AfterUpdate event or something
similar? The change event may not be desirable because it
fires each time the text box is changes. If you
type "1234" into the field this event fires four time.
AfterUpdate would probably be the best choice but you
might need to experiment depending on exactly what your
doing.

Hope that helps!

Kevin
 

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

Similar Threads


Top