OK. I agree t would result in many, many queries. Still trying to understand your real requirement.
What exactly are your ~22 bases?
Here's an idea.
Suppose you have your base SQL with its parameters -that doesn't work the way you want. And suppose you could, using some vba,
parse the Parameter query base and get the parameter names, loop through a dialog and get value for each parm, automatically do a replacement of parm with proper values and run the query. You get a result with this session of that parameter query. Youake no changes to the base.
Suppose you know the ~22 base queries, and you can invoke a process to select the query you want to process.
It does the replacement values and gets you the result -without changing your base query.
This doesn't have (without more design)
-any validation as such
-steps to ensure # are supplied for dates
-more
In effect you would have your 22 base queries and procedures to run them. You would supply the values for the parms and have logic to validate/adjust as needed.
You could have something like
Code:
Sub eric002()
Dim qdf As DAO.QueryDef
Dim prm As Integer
Dim p1 As String, i As Long
Dim arr
For Each qdf In CurrentDb.QueryDefs
If qdf.name = "ParmBase1" Then
For prm = 0 To qdf.Parameters.Count - 1
' Debug.Print qdf.Parameters(prm).name ', qdf.Parameters(prm).Type
p1 = p1 & qdf.Parameters(prm).name & "|" & InputBox("enter value for " & qdf.Parameters(prm).name, "My Title") & "|"
Next prm
' Debug.Print p1
End If
Next qdf
arr = Split(p1, "|")
' Debug.Print LBound(arr); UBound(arr)
For i = LBound(arr) To UBound(arr) - 1 Step 2
Debug.Print arr(i) & " >>VALUE >> " & arr(i + 1)
Next i
End Sub
that would produce a result :
Code:
[sdate] >>VALUE >> #4/1/24#
[edate] >>VALUE >> #11/30/24#
[andClause] >>VALUE >> cPosSizeR = 3
This could be adjusted and used with the earlier code(Eric001) to validate and supply values in the Replace functions.
I know the replacement SQL works. I did not find a way to get Eval to work, but it isn't something I use.
ParmBase1 was this Parameter query
Code:
PARAMETERS [sdate] DateTime, [edate] DateTime, [andClause] Text ( 255 );
SELECT Count(cPosSizeR) AS fieldValue
FROM StockTradesT
WHERE StockTradesT.TradeDate Between [sdate] And [edate] AND [andClause];
Added a ParmBase2
Code:
PARAMETERS [sdate] DateTime, [edate] DateTime, [andClause] Text ( 255 ), [andSymbol] text (10);
SELECT Count(cPosSizeR) AS fieldValue
FROM StockTradesT
WHERE StockTradesT.TradeDate Between [sdate] And [edate] AND [andClause] and [andSymbol]
Processed it to get
Code:
[sdate] >>VALUE >> #2/15/24#
[edate] >>VALUE >> #6/23/24#
[andClause] >>VALUE >> cPosSizeR <6
[andSymbol] >>VALUE >> Symbol ="Tesla"