variable as parameter in query

  • Thread starter Thread starter jonathan
  • Start date Start date
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
 
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
 
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
 
Back
Top