How to pass a VBA Variable Value to a query

A

Anthony

Is it possible to pass a VBA Variable Value into the criteria section of a
field in a query? (In design mode)
 
M

Marshall Barton

Anthony said:
Is it possible to pass a VBA Variable Value into the criteria section of a
field in a query? (In design mode)


No.

If you explained what you are trying to accomplish (instead
of how you thought you would do it), maybe someone will be
able to suggest an alternate approach.
 
A

Allen Browne

Just to be clear, in Access 2007 you can have variables that are available
in queries or in the control source of a text box.

TempVars are new. I haven't actually used them yet (beyond a quick test),
but they look promising.
 
G

Guest

Hi Anthony

In your VBA code create a function like the following one. VariableName is
your VBA variable.

Function FunctionName()
FunctionName = VariableName
End Function

In design mode of your query, right mouse click in the criteria box you wish
to use your function variable in. Select 'Build' option in the popup. Click
on 'Functions' to expand the list of functions. Select the VBA module your
function resides in. Your function should be listed in the right most
column. Double click it and OK. Bubda bing budda boom, your variable is the
criteria for your query.

For kicks click on the SQL view mode for your query (instead of Design View)
to see what the SQL code looks like.

Hope this helps
Norm
 
A

Anthony

that's dyna-mite!

thanks!

Norm said:
Hi Anthony

In your VBA code create a function like the following one. VariableName
is
your VBA variable.

Function FunctionName()
FunctionName = VariableName
End Function

In design mode of your query, right mouse click in the criteria box you
wish
to use your function variable in. Select 'Build' option in the popup.
Click
on 'Functions' to expand the list of functions. Select the VBA module
your
function resides in. Your function should be listed in the right most
column. Double click it and OK. Bubda bing budda boom, your variable is
the
criteria for your query.

For kicks click on the SQL view mode for your query (instead of Design
View)
to see what the SQL code looks like.

Hope this helps
Norm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top