The following example uses the TabStop property to control whether a user can press TAB to move the focus to a particular control. The user presses TAB to move the focus among the controls on the form, and then clicks the ToggleButton to change TabStop for CommandButton1. When TabStop is False, CommandButton1 will not receive the focus by using TAB.
To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:
Sub CommandButton1_Click()
MsgBox "Clicked CommandButton1."
End Sub
Sub ToggleButton1_Click()
Dim CommandButton1
Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")
If ToggleButton1 = True Then
CommandButton1.TabStop = True
ToggleButton1.Caption = "TabStop On"
Else
CommandButton1.TabStop = False
ToggleButton1.Caption = "TabStop Off"
End If
End Sub
Sub Item_Open()
Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1")
CommandButton1.Caption = "Show Message"
ToggleButton1.Caption = "TabStop On"
ToggleButton1.Value = True
ToggleButton1.Width = 90
End Sub