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

public variable not switching 1

Status
Not open for further replies.

tziviak2

MIS
Jul 20, 2004
53
0
0
US
I have a public variable set in a button's code:
Code:
 Option Compare Database
Option Explicit
Public rptAtt As Boolean

in the button's code-i'm calling a report to open up-and on the on-close of the form I'm setting:
Code:
 rptATT=false
but when it's coming back to the code-to continue the code-the rptatt's value is still true.
what am I doing wrong?
 
Do a global search for "rptATT" in your code.

Are you setting it somewhere else?

Is another instance of it being created locally that is hiding the global variable?

If it is Global to the form (i.e. declared in the Form's general declaration's section) then it won't be preserved when you close the form. Declare it in a module to make it an application-wide Public variable.
 
thank you-I moved the public statement to a module-how come I can't have in in a button on a form?-if it's public-it's public no? I guess not-but why not-any logic to it?
anyhow it's working so thank you
 

Declaring a Public variable in a Form makes it Global within that form only. All subs within that form will recognize it. In order for it to be recognized Globally outside of the form, i.e. by the report when it closes, it has to be declared, as you have now done, in a module. The logic is that it gives the programmer more control over the variable's SCOPE, which in essence means the programmer has more control. More control is always better.

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
any logic to it?

It would be very counter-intuitive to find a public variable in a private subroutine of a form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top