passing a global variable to query

wjfraser

New Member
Joined
Oct 17, 2006
Messages
2
Hello,

In Access 2000, I am trying to pass the value in a global variable to a query. I know this can't be done explicitly, but I've used a small function called get_global that returns the value of the variable. When I do this:

Code:
msgBox (get_global("KeyWordsSelected")

I get a message box with exactly the value I want (I am just doing this for debugging purposes; it is not a crucial element of the application). In this example, say it returns

'Air Quality'

When I take this value (that's in the message box) and copy it into my query, it works perfectly. For example:

Code:
WHERE (((tblSubProjectKeyWords.ProjectKeyWords)='Air Quality'));

However, when I use

Code:
WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=get_global("KeyWordsSelected")));

I get nothing returned.

I am trying to cobble this together with little training in SQL or Access, so I would appreciate any advice.

Additional information:
--get_global returns a string
--tblSubProjectKeyWords.ProjectKeyWords is a text field
--I have also tried storing the value I want in a text box, with the same result - a msgBox shows the correct value, but it does not resolve correctly within the WHERE statement.

Thanks!
Whitney
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

VicRauch

Well-known Member
Joined
Mar 23, 2006
Messages
2,032
I just tested what you have and it worked for me.

So, when that happens to me, I create a VERY simple query, and I would put this function into the "Field" row of the Query grid. Then, when the query is run, you will see the SQL is looking at when this function is placed in the Where clause. That should help you find the problem. Your code look correct.
HTH,
 

wjfraser

New Member
Joined
Oct 17, 2006
Messages
2
Thanks Vic,
I will try your suggestion, because I am very curious about why it doesn't work. However, I got it to work by building the query definition in the VB behind the button calling the query. For some reason that works when the other way didn't, even though in theory it should build out to exactly the same thing.

Thanks again,
Whitney
 

Forum statistics

Threads
1,136,600
Messages
5,676,727
Members
419,647
Latest member
usas12gthr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top