Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

How to prevent (TabKey) going to a command button ?

  Asked By: Hayfa    Date: Aug 10    Category: MS Office    Views: 717
  

In a Userform have 3 command buttons
How can I prevent the ( TabKey ) going to a command button ?
The ( TabStop ) is set to False

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Abbie Hughes     Answered On: Aug 10

That is the way.. are you sure you've got the right button?

 
Answer #2    Answered By: Myrtle Wilson     Answered On: Aug 10

Setting the TabStop to false  is how I do it. What else do you have
going on with your UserForm?

 
Answer #3    Answered By: Cain Smith     Answered On: Aug 10

And this is what I tried to do with the UserForm.

Sub OnlyFrames()

Application.ScreenUpdating = False
Sheets("Sheet1").Select
Sheets("Sheet1").Range("A1:F500") = ""
LoopInd = 0
lcount = 0
tabIdx = 0
Set myForm = UserForm10
Cells(2, 3) = "OBJECT NAME="
Cells(2, 4) = "TAB INDEX="
Cells(2, 5) = "TAB STOP="
Cells(2, 6) = "OPTBUTTON="
Cells(3, 3) = "UserForm10"

lcount = 3
LoopInd = LoopInd + 1
For Each cCont In myForm.Controls
If LoopInd > 1 Then Exit For
tabIdx = tabIdx + 1
lcount = lcount + 1
Cells(lcount, 3) = cCont.Name
'MsgBox ("TYPENAME: " & TypeName(cCont))
If TypeName(cCont) = "Frame" Then
Cells(lcount, 3).Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 5
End With
Else
Cells(lcount, 3).Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
End If
If TypeName(cCont) = "CommandButton" Then
Cells(lcount, 5) = cCont.TabStop
cCont.TabStop = False
cCont.TabIndex = tabIdx
Else
Cells(lcount, 5) = ""
End If
If TypeName(cCont) = "OptionButton" Then
Cells(lcount, 6) = cCont.Value
cCont.Value = False
cCont.TabIndex = tabIdx
Else
Cells(lcount, 6) = ""
End If
If TypeName(cCont) <> "Label" Then
Cells(lcount, 5) = cCont.TabStop
cCont.TabStop = True
cCont.TabIndex = tabIdx
Else
Cells(lcount, 5) = ""
End If
Cells(lcount, 4) = cCont.TabIndex
Next cCont
SendKeys "^{Home}"
Range("A1").Select

End Sub

 
Answer #4    Answered By: Aaeedah Khan     Answered On: Aug 10

As I told you before no time to really check this but there is something I did
see:
You don't need the LoopInd, since you do not do anything with it.
You first declare it, and then set  its value to 1 and then check if it's more
than 1 you exit the loop. It is never going to be more than 1 since you never
change it later on in your code. So no need for that. Just delete any line where
the loopInd appears.

 
Answer #5    Answered By: Lucio Ferrrari     Answered On: Aug 10

Here is some VBA code I found on the Internet to go thru all objects within each
Frame

Private Sub UserForm_Click()
Dim cCont As Control
Dim lCount As Long
On Error Resume Next

Cells(1, 1) = "NAME"
Cells(1, 2) = "TAB INDEX"
Cells(1, 3) = "TAB STOP"

lCount = 3
For Each cCont In Me.Frame1.Controls
lCount = lCount + 1
Cells(lCount, 1) = cCont.Name
Cells(lCount, 2) = "TabIndex=" & cCont.TabIndex
Cells(lCount, 3) = cCont.TabStop
Next cCont

For Each cCont In Me.Frame2.Controls
lCount = lCount + 1
Cells(lCount, 1) = cCont.Name
Cells(lCount, 2) = "TabIndex=" & cCont.TabIndex
Cells(lCount, 3) = cCont.TabStop
Next cCont

For Each cCont In Me.Frame3.Controls
lCount = lCount + 1
Cells(lCount, 1) = cCont.Name
Cells(lCount, 2) = "TabIndex=" & cCont.TabIndex
Cells(lCount, 3) = cCont.TabStop

Next cCont
End Sub

 
Answer #6    Answered By: Amanda Carter     Answered On: Aug 10

Here is the updated VBA code to set  the ( TabIndex ) & ( TabStop ) just prior to
a UserForm being loaded in
Anyway a concept I now do on most UserForms, is to place all objects( TextBoxes
and Optionbuttons ) sequentially in numbered order inside a Frame
With this concept I can do the ( TabStop=FALSE ) on a Frame, so the none of the
objects inside the specfic frame aren't tabbed to
For example, in another Userform I have optionbuttons inside a frame I didn't
want to be tabbed to with the ( TabKey )
Then with the code below, most Userforms comes out perfect with the ( TabKey )
sequence in sequential order.


Application.ScreenUpdating = False
tabIdx = 0
Set myForm = UserForm10
For Each cCont In myForm.Controls
tabIdx = tabIdx + 1
'MsgBox ("TYPENAME: " & TypeName(cCont))
Select Case TypeName(cCont)
Case "Frame"
cCont.TabStop = True
cCont.TabIndex = tabIdx
Case "CommandButton"
cCont.TabStop = False
Case "OptionButton"
cCont.Value = False
cCont.TabStop = True
cCont.TabIndex = tabIdx
Case "ComboBox"
cCont.TabStop = False
Case "TextBox"
cCont.TabStop = True
cCont.TabIndex = tabIdx
Case "Label"
'nothing here
End Select
Next cCont
'UserForm10.Show

 
Didn't find what you were looking for? Find more on How to prevent (TabKey) going to a command button ? Or get search suggestion and latest updates.




Tagged: