How to: Accept User Input and Display the Values of Controls on a Form

The following example demonstrates the values that the different types of controls can have by displaying the Value property of a selected control. The user chooses a control by pressing TAB or by clicking on the control. Depending on the type of control, the user can also specify a value for the control by typing in the text area of the control, by clicking one or more times on the control, or by selecting an item, page, or tab within the control. The user can display the value of the selected control by clicking the appropriately labeled CommandButton.

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() 
 Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1") 
 Set Form = Item.GetInspector.ModifiedFormPages("P.2") 
 TextBox1.Text = "Value of " &; Form.ActiveControl.Name &; " is " &; Form.ActiveControl.Value 
End Sub 
Sub Item_Open() 
 Set CommandButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CommandButton1") 
 Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1") 
 Set ComboBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox1") 
 Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1") 
 Set CheckBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("CheckBox1") 
 Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1") 
 Set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2") 
 CommandButton1.Caption = "Get value of current control" 
 CommandButton1.AutoSize = True 
 CommandButton1.TakeFocusOnClick = False 
 CommandButton1.TabStop = False 
 TextBox1.AutoSize = True 
 For i = 0 To 10 
 ComboBox1.AddItem "Choice " &; (i + 1) 
 ListBox1.AddItem "Selection " &; (100 - i) 
 CheckBox1.TripleState = True 
 ToggleButton1.TripleState = True 
 TextBox2.Text = "Enter text here." 
End Sub