Tab Order Problem

M

Minitman

Greetings,

I have a UserForm with 14 TextBoxes (TB1 - TB14) and 1 CheckBox
(CBX1). The tab order is: TB1, TB2, TB3, TB4, TB5, TB6, CBX1, TB7,
TB8, TB9, TB10, TB11, TB12, TB13, TB14. I can use the Enter key to
get to CBX1 and then I can't get any further (the tab key does work
but I would rather not). Is there something different about the
CheckBox that wont allow the Enter key to advance the focus to the
next TextBox?

Any ideas on how to get this to work?

TIA

-Minitman
 
T

Tom Ogilvy

I guess that is because the typical interaction with a checkbox is not using
the enter key. You can manage it in code:

Private Sub CheckBox1_KeyDown(ByVal KeyCode As _
MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
tIdex = CheckBox1.TabIndex + 1
If tIdex >= Me.Controls.Count Then
tIdex = 0
End If
For Each ctrl In Me.Controls
If ctrl.TabIndex = tIdex Then
ctrl.SetFocus
Exit For
End If
Next
End If
End Sub

Private Sub CheckBox2_KeyDown(ByVal KeyCode As _
MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
tIdex = CheckBox2.TabIndex + 1
If tIdex >= Me.Controls.Count Then
tIdex = 0
End If
For Each ctrl In Me.Controls
If ctrl.TabIndex = tIdex Then
ctrl.SetFocus
Exit For
End If
Next
End If
End Sub

Private Sub CheckBox3_KeyDown(ByVal KeyCode As _
MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
tIdex = CheckBox3.TabIndex + 1
If tIdex >= Me.Controls.Count Then
tIdex = 0
End If
For Each ctrl In Me.Controls
If ctrl.TabIndex = tIdex Then
ctrl.SetFocus
Exit For
End If
Next
End If
End Sub
 
M

Minitman

Hey Tom,

I just tried 1 of these subs and after DIMing the 2 variables (tIdex
and ctrl), it works great.

Thanks.

-Minitman
 
T

Tom Ogilvy

Depends on whether you have option explicit or not. If not, works great
without dimming, but it is usually better to have it and dim them.
 

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

ComboBox & TextBox Problem 6
Find textboxes on a form ? 4
Stop TextBox Clearing Cell 3
Userform problem? 4
UserForm Text Box Percentage 6
Code Wont Work 2
Creating a function 3
Code Still Does Not Work 8

Top