WHERE f$

  • Thread starter Thread starter JethroUK
  • Start date Start date
J

JethroUK

How do i pass a global variable (as criteria) to a Query design/SQL?

The variable f$ will contain an sql where statement e.g. "[Enquired] Is Not
Null AND [Letter Sent] Is Null"

Works fine if i just copy/paste into the SQL statement, or criteria line in
design

But I have to pass it as a variable (it will change according to a form
filter)

It has to be part of a query design because this in turn is used by a
mail-merged letter
 
JethroUK said:
How do i pass a global variable (as criteria) to a Query design/SQL?

The variable f$ will contain an sql where statement e.g. "[Enquired] Is Not
Null AND [Letter Sent] Is Null"

Works fine if i just copy/paste into the SQL statement, or criteria line in
design

But I have to pass it as a variable (it will change according to a form
filter)

It has to be part of a query design because this in turn is used by a
mail-merged letter

You'll have to use code to change the SQL property of the query on the fly prior
to running the merge.

CurrentDB.QueryDefs("QueryName").SQL = "Base SQL " & f$
 
This has been paining me for weeks - Thankyou


Rick Brandt said:
JethroUK said:
How do i pass a global variable (as criteria) to a Query design/SQL?

The variable f$ will contain an sql where statement e.g. "[Enquired] Is Not
Null AND [Letter Sent] Is Null"

Works fine if i just copy/paste into the SQL statement, or criteria line in
design

But I have to pass it as a variable (it will change according to a form
filter)

It has to be part of a query design because this in turn is used by a
mail-merged letter

You'll have to use code to change the SQL property of the query on the fly prior
to running the merge.

CurrentDB.QueryDefs("QueryName").SQL = "Base SQL " & f$
 
You can create a function that returns the variable value:
Public Function YourFunc()
YourFunc = f$
End Function

Select .....
From ...
Where YourField = YourFunc();

I prefer to use hidden form rather than global variables. So, in that case
the query would be:
Select ....
From ...
Where YourField = Forms!frmHidden!YourField;
 

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

Back
Top