Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interchangeable form control criteria

Status
Not open for further replies.

SKIGAL

Technical User
May 12, 2003
11
US
I have a base query where the criteria is based on a form control. I have a 'sum' query built on top of this query. The click event on a form will drive code that looks up a value from the 'sum' query.

The question is, how do I reference the form controls in the query criteria if I want to use this query for multiple forms and the criteria will pull from the active or current form?

Thanks in advance for your assistance!

:->


 
You can dynamically change the SQL of a query.

'Open the query as a QueryDef
dim qdf as querydef

set qdf = currentdb.QueryDefs("YourQueryName")
qdf.sql = left(qdf.sql, instr(qdf.sql, _
" WHERE ")-1 & " WHERE " & txtYourNewCriteria
qdf.close


Just make sure that the form is modal so two forms using the same query cannot be opened at one time.
 
The easiest way I think of is you may want to use a function. E.G.

Create a module with a simple function and public variable:
Public criteria as string
Public Function QueryCrit as string
Return criteria
End Function

In the forms, on an event (such as clicking a button that generates the query):
Sub OnClick
criteria = "Smith"
end sub

In the query, in the criteria:
QueryCrit()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top