Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a public variable from a form 1

Status
Not open for further replies.

xtraterrestrial

Programmer
Sep 23, 2003
38
CA
Hi

I wanna get access a public variable in a form from a subform of the form. Is there a way to do this ?

Thanks
 
Hi xtraterrestrial,

This would return the value of "MyVariable" in the Main Form to the Sub Form:

Me.Parent.MyVariable

Bill
 
Dear Xtra,

If you Create a 'module' file and define the variable in the module, as public, then all forms and modules can use and share the variable.

Example:
[Blue]
Public MyVar as string ' Place this in the 'module'
[Black]
Now you can access the 'MyVar' anywhere but a query.
If you want to also access the variable in a Query, the in the same Module that you defined the variable, add this function:
[Blue]
Public MyVar as string ' Place this in the 'module'
Public Function PassMyVar() As String
PassMyVar = MyVar
End Function
[Black]
Now, you can see the value of the variable anywhere.

Hope this Helps,
Hap [2thumbsup]

define the

Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
hi billpower

I tried your suggestion and it doesn't seem to work
I get an "application-defined or object-defined error"
 
Hi Hap007,

I meant to say that too, thanks for pointing it out. Think that deserves a * .

xtraterrestrial,

I would go with Hap's suggestion unless you have a specific reason for not wanting to declare a Global variable. I can't see how or where you've declared the variable in the main form so can't really suggest anything otherwise.

Good Luck

Bill
 
I just declared it like

Option Compare Database
Dim currentTaskID As Integer

at the very top of the form.

I will try Hap's suggestion, it just seemed like a lot of work for something so simple.

Thanks for your help
 
Hi xtraterrestrial,

You should have declared the variable as:

Public currentTaskID As Integer

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top