您可以随时使用替换。
sSQL = "SELECT lots of sql WHERE LocationID IN (qqlocidqq)"
sSQLWithLoc = Replace (sSQL, "qqlocidqq", "1,2,3,4")
Dim qdf As QueryDef
'A query that exists
Set qdf= CurrentDB.QueryDefs("MyJunkQuery")
'Permanently change the sql of that query
qdf.SQL = sSQLWithLoc
进一步研究一下,它可能适合您使用Instr,如下所示:
SELECT Table1.LocationID
FROM Table1
WHERE InStr([@List],[LocationID])>0
这样测试:
PARAMETERS Number_List Text(50);
TRANSFORM Count(Table1.AKey) AS CountOfAKey
SELECT Table1.AText
FROM Table1
WHERE InStr([Number_List],[ANumber])>0
GROUP BY Table1.AText
PIVOT Table1.ANumber;
其中,表1由字段AKey、AText和ANumber组成。Number_List是由参数提供的数字的逗号分隔列表。Instr检查提供的参数中是否存在表1中的ANumber。
重叠1,2,12存在问题,但创造性地使用逗号可能适合:
WHERE InStr("," & [Number_List] & "," , "," & [ANumber] & ",")>0
当然,分隔符不必是逗号,|通常很有用。