I have an application consisting of 2 forms (Form1 and Form2).
There is a text box on each form and they are both named Text1.
From a sub routine in a module, I want to alter a text box on one of the forms. The sub determines which form to write to and attempts to refer to the form using a variable.
But in the example below, gForm never gets declared when it’s nested within the If statement.
Public Sub DoSomething
If gState = True then
Dim gForm as Form1
Else
Dim gForm as Form2
End if
gForm.Text1.text = ”Hello”
End Sub
This example fails because Form and Form1 (or Form2) are not directly compatible.
Public Sub DoSomething
Dim gForm as Form
If gState = True then
gForm = Form1
Else
gForm = Form2
End if
gForm.Text1.text = ”Hello”
End Sub
The actual application is not so simple and I need to use this or a similar approach throughout the application in order to reduce code redundancy.
To recap, I want to alter a control on a form by replacing the form name with a variable name.
For example, instead of…
Form1.Text1.Text = ”Hello”
I want…
MyVar.Text1.Text = ”Hello”
How can I accomplish this? Thanks!
There is a text box on each form and they are both named Text1.
From a sub routine in a module, I want to alter a text box on one of the forms. The sub determines which form to write to and attempts to refer to the form using a variable.
But in the example below, gForm never gets declared when it’s nested within the If statement.
Public Sub DoSomething
If gState = True then
Dim gForm as Form1
Else
Dim gForm as Form2
End if
gForm.Text1.text = ”Hello”
End Sub
This example fails because Form and Form1 (or Form2) are not directly compatible.
Public Sub DoSomething
Dim gForm as Form
If gState = True then
gForm = Form1
Else
gForm = Form2
End if
gForm.Text1.text = ”Hello”
End Sub
The actual application is not so simple and I need to use this or a similar approach throughout the application in order to reduce code redundancy.
To recap, I want to alter a control on a form by replacing the form name with a variable name.
For example, instead of…
Form1.Text1.Text = ”Hello”
I want…
MyVar.Text1.Text = ”Hello”
How can I accomplish this? Thanks!