|
Question : SQL criteria applied to nested queries
|
|
I have a report that uses a query as the record souce. The query used in the report contains 3 nested queries that perform separate calculations. I call the report from a parameter FORM using the following code: If ViewType = myPRINT Then DoCmd.OpenReport ReportName, acViewNormal, , SelectionSQL, , ReportType Else DoCmd.OpenReport ReportName, acViewPreview, , SelectionSQL, , ReportType DoCmd.RunCommand acCmdFitToWindow End If
The SelectionSQL is generated from the data entered on a Form (up to 30 different selection ranges). This method works on single layer queries, but with a multiple level query the SelectionSQL is not applied to the nested queries (selects all records). How can I make the nested queries utilize the SelectionSQL?
I tried changing the SQL of the query using something like: Set CurrDb = CurrentDb() WhereStmt = " WHERE (" & SelectionSQL & ");" CurrentDb.QueryDefs("QryRTypeRateDetail").SQL = _ Replace(CurrentDb.QueryDefs("QryRTypeRateDetail").SQL, ";", WhereStmt) Set CurrDb = Nothing
This just appends the WHERE statement to the query after replacing the terminating ";" character. The problem is the second iteration requires different logic to filter out the old WHERE statement and replace with a new WHERE statement. I can probably figure out how to write this code, but the process is VERY messy.
Is there a clean way to set a filter on a query without changing the entire SQL? I tried things like: CurrentDb.QueryDefs("QryRTypeRateDetail").Properties("Filter") = SelectionSQL CurrentDb.QueryDefs("QryRTypeRateDetail").Properties![Filter] = SelectionSQL But they all give syntax errors. Couldn't figure out how to set the filter property on my query.
Any help anyone can give me would be greatly appreciated. I am in a big rush for this.
|
|
Answer : SQL criteria applied to nested queries
|
|
PAQed with points refunded (500)
Computer101 EE Admin
|
|
|
|