Tab key not working with textboxes - KeyCode=9 not being recognized

S

SS

Hello all,

I have three textboxes that I created by clicking on the textbox icon in the
control toolbox. For each of these textboxes I have the following code:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 9 Then Me.TextBox2.Activate
End Sub

Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 9 Then Me.TextBox3.Activate
End Sub

Private Sub TextBox3_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 9 Then Me.TextBox1.Activate
End Sub

When I click on the first textbox and hit enter, the code does what I want
it to do i.e. the focus moves the focus from TextBox1 to TextBox2. But when
I hit tab again, instead of the focus moving from TextBox2 to TextBox3, a
tab character is entered in TextBox2. If I click outside any of the boxes,
then click in TextBox2 and hit tab, it works fine again i.e. the focus moves
from TextBox2 to TextBox3. Why doest my focus move from TextBox2 to
TextBox3 without going through the deselcting and selecting operation with
the mouse? How can I fix it?

Please help.
SS
 
A

Anand.V.V.N

Hi SS,

I tried the code, I observed that if me. removed it dosn't happen, so insted
of me.textbox.activate, just uset textbox.activate


insted of

If KeyCode = 9 Then Me.TextBox2.Activate

try

If KeyCode = 9 Then TextBox2.Activate

Hope you find this works for you

Anand
 
A

Anand.V.V.N

Hi SS,

I'll try with and see. Any way one possible work aroudn would be to have a
form in which these textboxes can be displayed, or when the user presses the
tab key switch to the "In line with text" and go to the next textbox and
then switch back to the "In front of text" wraping style, I am not sure if
this possibel though, I'll try and see.

Anand
 
A

Anand.V.V.N

Hi SS if you allowed to use forms it'll make it easy, any way I am trying on
that changing layout thing let me see how successful it might be.

Anand
 

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