Global Variables

  • Thread starter Thread starter BigAppa
  • Start date Start date
B

BigAppa

Guest
How do you create global variables? I want a report to be able to recognize a property that is set in a form. I tried declaring the variable on the top of the form but when a report is opened from the form and I try to access the variable from the form, an error appears saying that the variable isn't recognized. Please help!


Thanks
 
You need to declare global variables in a module. Create a new module named modVariables or somesuch and use

Public Var as Variant

or whatever.
 
I agree with what charity posted above but wanted to post an alternative anyway...

You can call your private var by making a public property in your form

Code:
Dim intInt As Integer

Private Sub Form_Open(Cancel As Integer)
    'or whatever you are doing to ste the value of your var
    intInt = 23
End Sub

Public Property Get MyProp() 
    MyProp = intInt
End Property
you can then call the property by using

newVar = Forms!FormName.MyProp in your
report. But if the value is already on your form in a text box or similar then you should be able to call it directly as Forms!YourForm!YourFieldName

Anyway hope that makes sense even if charity's is way easier!

Drew
 

Users who are viewing this thread

Back
Top Bottom