Problem using tab in TextBoxs not in userform

E

Excel Curious

I've got six Text boxes (TextBox1...TextBox6) they are NOT in a user form. I
want to be able to Tab between them and was trying to use the following code,
but found that it only worked for the first item and thereafter I'd have to
go in and "click" on the next text box to select it before I could tab again
to the next. Somehow the second use of the KeyDown is not working as I
thought.


Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Dim fldTemp

If KeyCode = 9 Then
TextBox2.Activate
End If
End Sub

Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Dim fldTemp

If KeyCode = 9 Then
TextBox3.Activate
End If
End Sub

....and so on.
 
W

Wolfgang Kais

Hello "Excel Curious" .

Excel Curious said:
I've got six Text boxes (TextBox1...TextBox6) they are NOT in a user
form. I want to be able to Tab between them and was trying to use
the following code, but found that it only worked for the first item
and thereafter I'd have to go in and "click" on the next text box to
select it before I could tab again to the next. Somehow the second
use of the KeyDown is not working as I thought.

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim fldTemp

If KeyCode = 9 Then
TextBox2.Activate
End If
End Sub

Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim fldTemp

If KeyCode = 9 Then
TextBox3.Activate
End If
End Sub

...and so on.

Set the TabKeyBehaviour property to true and use code like this:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = vbKeyTab Then
KeyAscii = 0
Me.TextBox2.Activate
End If
End Sub

.... and so on.
 
E

Excel Curious

It doesn't seem to be working. When I press Tab nothing happens. I didn't
think you could use Tab with Keypress since it requres a KeyAscii, and the
tab is a keycode.

Any other suggestions???

Thank You
 
W

Wolfgang Kais

Hello "Excel Curious".

Excel Curious said:
It doesn't seem to be working. When I press Tab nothing happens.
I didn't think you could use Tab with Keypress since it requres a
KeyAscii, and the tab is a keycode.

Any other suggestions???

Have you set the TabKeyBehaviour property to true for all textboxes?
Also, be sure to leave the edit mode before testing.
Depending on your macro security, the code may be blocked when it is
not digitally signed with a trusted certificate.
Tab is a character with ascii code 9.
 
E

Excel Curious

I've checked everything. I even put three textboxes in a new Word document to
test them on their own. When pressing Tab in the first box it will go to the
second, but when Tab is pressed in the second box and actual Tab occurs. Is
there a way to send my test document?

I don't typically have such trouble with my Macros, thank you for trying to
help me with this issue.
 
W

Wolfgang Kais

Hello.

Excel Curious said:
I've checked everything. I even put three textboxes in a new Word
document to test them on their own. When pressing Tab in the first
box it will go to the second, but when Tab is pressed in the second
box and actual Tab occurs. Is there a way to send my test document?

In such cases, it might be beneficial to post using your real name.
Would you like to post your email address (I don't)? If you do,
I'll send you an email that you can answer and send the file.
I don't typically have such trouble with my Macros, thank you for
trying to help me with this issue.

You're wellcome. It's one of my favourite hobbies to make people happy.
 
E

Excel Curious

See below

Wolfgang Kais said:
Hello.



In such cases, it might be beneficial to post using your real name.
Would you like to post your email address (I don't)? If you do,
I'll send you an email that you can answer and send the file.
(e-mail address removed)


You're wellcome. It's one of my favourite hobbies to make people happy.
 
E

Excel Curious

Okay, I’ve got one last issue. I’ve linked my “form†to our companies
intranet and when opened it defaults to opening Word in the browser window.

Somehow, the code to use the tab key to go between text boxes is disabled.
Pressing the tab key behaves as a tab in the textbox. All other macros on the
document still work fine.

I cannot change all users Explorer options to disable the “browse in same
window†function.

This document is also protected and I had to adjust the tab code to use
select, rather than activate.
 

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