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 Westi 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 available in another form 2

Status
Not open for further replies.

alr0

Programmer
May 9, 2001
211
US

Hi All

I have a form (Access 03) that calculates some statistics in the OnOpen event that can take a long time for large files. I would like to give users the choice of not running these calculations. If the file is over 1 meg a modal popup form with two buttons opens and sets a variable based on which button the user selects. The variable is declared as public in the original form but is not available in the second form.

Restated:

Form A has the line:

Public intOptTyp as integer

In the OnOpen event of form A, form B is opened and tries to assign a value to intOptTyp but it errors out with the message "variable not defined". (Each module has an Option Explicit statement, of course)

Gosh, this seems so easy! Is it obvious where I went wrong?

Thanks,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
And this ?
Forms![form A].intOptTyp = yourValue

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Hello again PHV,

I tried:

Forms![frmWkDt].intOptTyp = 1

and got the following error:

"Application-defined or object-defined error"

Oh dear, what could the matter be?

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Why not opening form B in the Load event of form A instead of the Open ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Hi PH,

I moved the code to the OnLoad event but it does not make any difference, same error message. I am curious why that would make any difference to the availablality of the variable.

The error occurs in form B when I am making the assignment as the result of the user clicking one of the two buttons.

This should be simple stuff, no?

Thanks,

alr



_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Where exactly is located the Public declaration of intOptTyp ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I appears in the top section of the form module with the other statements listed below.

Option Compare Database
Option Explicit
Dim appAccess As Access.Application
Public intOpnTyp As Integer
Public FlSz As Long

Is this not correct?

Thanks

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Fine.
Do you know how to debug step by step your code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yes I do.

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
The variable is declared as public in the original form but is not available in the second form.

The variable needs to be declared in an independent module, not in a form's module, to be available throughout your DB.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks for your help! I got the variable to be recognized but got pulled of on some other work. I will be back at this in a few weeks.

Thanks again,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Don't you hate when that happens? [upsidedown]

Have a good weekend!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top