capture value as global variable

J

jonathan

Hi, when i hit a button i want it to capture a value on my form and store it
as a global variable.
Then i want recall that variable for a new record on another form. Can some
one point in the right direction
thx
jonathan
 
J

Joshua A. Booker

Jonathan,

Add this code to a new Module:
...........................................................
'Declare the global variable
Public VarName as Variant

Public Function SetGlobal(stValue as Variant)
'This function accepts a value and sets the gloabal variable to it
VarName = stValue
End Function

Public Function GetGlobal() as Variant
'This function returns the value of the gloabal variable
GetGlobal = VarName
End Function
...............................................................

Add this code to the form module for setting the global variable
.............................................................................
.......
Private Sub ButtonName_Click()
SetGlobal (Me!TextBox1.Value)
End Sub
.............................................................................
......

Add this code to the other form module for retreving the variable

.............................................................................
......
Private Sub ButtonName_Click()
Me!Textbox1 = GetGlobal()
End Sub
.............................................................................
.......

Assuming your buttons are called ButtonName and your text boxes are called
Textbox1. You can rename the variable as long as you do it everywhere.

HTH,
Josh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top