Variablere trieving from another form

John thomas

Registered User.
Local time
Yesterday, 17:11
Joined
Sep 4, 2012
Messages
206
Hi Im new to access programming.Is it possible to store a variable in one form and then retreive it to auto fill a field on another form .
I know hot to Dim and store on the same form but trying to retreive from another form i cant do .
I presume the seconf form would be something like this OnLoad Variable=forms"customers"customersFK But i have no real idear
 
Rather than declaring the variable in the form module, declare it in a standard module:

Public VariableName As DataType

and it will be available anywhere in VBA.
 
Generally, global variable should be used for global purposes and this does not sound like one.

Instead make it a public variable in the declarations section at the top of first form's module and refer to it as:

Forms!formname.variablename

However if the second form is being opened by the first it is best to pass the value of the variable with the open command via the OpenArgs argument of the OpenForm method. It becomes the OpenArgs property (a string) of the form that is opened.
 

Users who are viewing this thread

Back
Top Bottom