TRANSFORM IIF(IsNull(First(wrhCode)),'' ,First(wrhCode) & ', ' ) AS FirstOfwrhCode
SELECT whiitemID AS ItemID,
whiItemName AS Name,
Sum(Qty) AS Quantity
FROM (SELECT wrhID,
wrhCode,
whiitemID,
whiItemName,
Sum(whiQty) AS QTY
FROM tblWarehouseItem AS WI
INNER JOIN tblWarehouse AS W ON WI.whiwrhID = W.wrhID
WHERE whiActive = True
AND whiwrhID IN (Forms.frmStockControl.Form.txtwrhIDs)
GROUP BY wrhID, wrhCode, whiItemName, whiitemID) AS [%$##@_Alias]
GROUP BY whiitemID, whiItemName
PIVOT 'wrhID' & wrhID;
我对我的表单有这个查询但它不起作用: 但如果我编辑:
AND whiwrhID IN (Forms.frmStockControl.Form.txtwrhIDs)
为:
AND whiwrhID IN (26,27,29)
正在处理任何想法如何修复错误
答案 0 :(得分:1)
你不能。
whiwrhID IN (26,27,29)
必须在SQL中进行硬编码。
您唯一的选择是在调用查询之前调整SQL。
答案 1 :(得分:1)
为什么不use VBA to build a dynamic query?
您可以通过事件或宏启动子MakeAQuery,将IN
语句修改为您需要的任何内容:
Sub MakeAQuery()
Dim db As DAO.Database
Dim strSQL As String
Dim strElements As String
Set db = CurrentDb()
'Your current SQL with a parameter in the IN clause
strSQL = "TRANSFORM IIF(IsNull(First(wrhCode)),'' ,First(wrhCode) & ', ' ) _
AS FirstOfwrhCode _
SELECT whiitemID AS ItemID, _
whiItemName AS Name, _
Sum(Qty) AS Quantity _
FROM (SELECT wrhID, _
wrhCode, _
whiitemID, _
whiItemName, _
Sum(whiQty) AS QTY _
FROM tblWarehouseItem AS WI _
INNER JOIN tblWarehouse AS W ON WI.whiwrhID = W.wrhID _
WHERE whiActive = True _
AND whiwrhID In ({0})_
GROUP BY wrhID, wrhCode, whiItemName, whiitemID) _
AS [%$##@_Alias]
GROUP BY whiitemID, whiItemName
PIVOT 'wrhID' & wrhID;"
' Retrieve your IDs for the IN clause
strElements = Forms.frmStockControl.Form.txtwrhIDs
' Assign SQL to query
db.QueryDefs!YourQuery.SQL = Replace(strSQL, "{0}", strElements)
End Sub
将此VBA子分配给表单上的按钮或其他控件...
Layout View
获取表单。Event
标签。OnClick
可以正常工作。)Code Builder
和Ok
。 Call MakeTheQuery
放入它为您构建的子目录中。 答案 2 :(得分:-1)
请改为尝试:
Forms.frmStockControl.Form.txtwrhIDs.Text