Passing Variables

  • Thread starter Thread starter Keith
  • Start date Start date
As long as both forms are open (1 can be visible while the other is hidden
and vice versa) then you just reference it like below
TextBox1 on Form1 control source property
=[Forms]![Form2]![TextBox2]
TextBox2 on Form2 control source property
=[Forms]![Form1]![TextBox1]
 
You could also use a global variable. Go to the VB Editor and Insert a Module.

At the very top define the variable. For a string:
Dim gblstrString as string

Now code one sub and one function:

public sub SetString(byval strString as string)
gblstrString = strString
end sub
public function GetString() as string
GetString = gblstrString
end function

Then in the lost_focus code for the form put
Call SetString(FormField.value) ' where FormField is the name of the
form's field

In the new form, in On_Open code put
NewFormField = GetString()

Make sure that both FormFields are defined the same type or use the convert
function of VB.

John H W
 
Back
Top