This example passes a control from a form that doesn't have the focus to a procedure in a module, and then displays the state of the control on the parent form. To try this example, create three forms: Form1, containing a CommandButton control, and Form2 and Form3, each containing a CheckBox control. You must also create a new module (click Add Module in the Project menu). Paste the code into the Declarations sections of the respective forms or module, and then press F5 to run the program.
' Enter this code into Form1.
Private Sub Form_Load ()
Form2.Show ' Display all forms.
Form3.Show
Form2.AutoRedraw = True
Form3.AutoRedraw = True
End Sub
Private Sub Command1_Click ()
ReadCheckBox Form2.Check1 ' Call procedure in other module
ReadCheckBox Form3.Check1 ' and send control as argument.
End Sub
' Enter this code into Module1.
Sub ReadCheckBox (Source As Control)
If Source.Value Then
Source.Parent.Cls ' Clear parent form.
Source.Parent.Print "CheckBox is ON." ' Display on parent form.
Else
Source.Parent.Cls ' Clear parent form.
Source.Parent.Print "CheckBox is OFF." ' Display on parent form.
End If
End Sub