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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaring Form1 Variable For Use With Form2

Status
Not open for further replies.

Caper

Technical User
Aug 11, 2001
9
US
I'm new to this stuff so forgive what is probably an easy question. I'm using the following statement in the General section of the module for Form1:

Public iID As Integer

The iID variable eventually gets set to a number. When I open Form2 and try and populate a text field with the value held by the iID variable all I get is 0. I've used a series of msgboxes to determine that the variable stays set for as long as Form1 is open, but when Form1 is closed the variable gets reset to 0. I've worked around this "problem" by using code to make Form1 invisible, which keeps iID holding the number, but I thought Publicly declared variables were supposed to hold their value even after the form that called them was closed.

Am I understanding Public declarations correctly? Thanks for any guidance!
 
hi,

if you want to keep your var at all times, create a module in which you declare it public, then you can access it in both forms at all time.

grtz

cpuburn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top