variable as parameter in query

J

jonathan

Hi all,
I have a summary button a form that lauches the summary form, this is based
on a query. When i hit the summary button it stores a string value in a
global variable. My question is, can my query pick up this variable and use
it as an in parameter.
I was thinking of using a tmp form to variable in a txtbox and have the
query pick this up. The reason for doing this i want to use the same summary
form and query many times over called from lots of diff forms.
cheers
 
J

Jen

Hi,

So, when you launch this summary form, you basically want
a query to run WHERE some field = global variable? If so,
you can do something like this:

DoCmd.OpenForm "summary_form_name",
acNormal, , "field_name ='" & variable_name & "'"

The field name would be the field name in the query that's
underlying your form. Make sure you change the rest of
the data in the above statement to suite your particular
situation. The above syntax assumes that the variable and
field data types are text (hence the single quotes.

Regards,
Jen
 
J

John Vinson

My question is, can my query pick up this variable and use
it as an in parameter.
I was thinking of using a tmp form to variable in a txtbox and have the
query pick this up. The reason for doing this i want to use the same summary
form and query many times over called from lots of diff forms.

You can't reference a VBA variable directly in a Query - they are
different boxes!

You can either write a silly little wrapper function:

Public Function GetGlobal() As Variant
GetGlobal = glbYourVariable
End Function

and use *it* as the criterion; or, if the value is in a control on an
open form, simply reference the form control itself as your criterion:

=Forms!yourform!yourcontrol
 

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