Global var

KenHigg

Registered User
Local time
Today, 04:08
Joined
Jun 9, 2004
Messages
13,291
Quick question that I suddenly have gotten stuck on: How do I use a global var in the query builder grid as a parameter? It keeps putting quotes around it - ?!
 
Sorry Unc, That went right over my head - ? :p
 
Yes. What's the difference?
 
I can get to it in any code anywhere so I guess it should be avail to use as a param in the query builder...
 
I think that you may need to provide a function to read the Global variable for you. I am not sure but I think that SQL can't access variables directly but it can call a function to get the value.
 
if you have a global var (and i use them ALL the while - i never read variables off a form )(well hardly ever)

you need a function

so

dim myvar as long

function readmyvar as long
readmyvar = nz(myvar,0)
end function


------
nowe in your query you use

=readmyvar() {you MUST include the brackets} to read the variable
 
Thanks all - I guess I'll look at doing a function...
 
Hey Ken,

You doing a gig for somebody who needs an app???

Your initial question sooooo points to that.
 
I'm doing a revision for an app I built that I support - :)
 
JBurlison

surely it is far easier to use a global variable than to try and hide forms/close them etc etc - that seems a hard way to do it, to me.

you do have to keep track of the variables used, so you dont inadvertently reset them inappropriately

if you want to get fancy, you can put them INSIDE a type declaration, then you get intellisense, so you dont even have to remember the names.
 
'INSIDE a type declaration' How do you do that? - I read something on it somewhere but it escapes me... :)
 
JBurlison

you do have to keep track of the variables used, so you dont inadvertently reset them inappropriately

I used to declare all mine in their own module and used a prefix pub on their names. The value of this was brought home to me when helping a poster on the forum debug a problem that turned out to be that as she had a variable in a little used class module named the same as an extensively used public variable..

I look foreward to your reply to Ken as I never ever used that technique.

brian
 
in a module

type tmyvariables
gblDate as date
gblCustomerNum as long
'etc
end type

then

public myvars as tmyvariables


now as you type

custnum = myvars.
or
myvars.

the intellisense will bring up all the members of the tmyvariables type

------
its a sort of halfway house to using a full class.
 
Cool. I'll have to try that.

Here's another kind'a related question: New .mdb. New module. I declare a constant, say 'myConst'. Now without saving that module, I open another new module and in the immediate window I do ?myConst. and it displays the value I assigned it in the other module. So - Is it safe to assume that if vba encounters a string (say anywhere in my app I do something like 'msgbox myConst'), it runs through all of the modules to see if it can if it can find where a constant has been declared with the same name? Or does it somehow, after you type in the 'public const ' statement, place all of the constants in some kind of holding spot in memory?
 

Users who are viewing this thread

Back
Top Bottom