我试图通过组合一些表来获取某些项目的itemid和数量,但是我收到以下错误:" OBJECT VARIABLE OR BLOCK WITH VARIABLE NOT SET" 任何人都可以找到我的代码的解决方案是:
openRecSet cmRPTItem, tmp, "SELECT ITEMS.ITEMID, ROUND(SUM(QTY),2) as SQty FROM (SELECT ITEMID,OPNSTOCK AS QTY,FLOOR(OPNSTOCK/PACKING) AS PTY FROM ITEMS WHERE " & _
" ITEMID = '" & rsRPTItem.Fields(0) & "' UNION ALL SELECT ITEMID,QTY=SUM(CASE RET WHEN 'N' THEN -1 * (ABS(QUANTITY) + ABS(FREE)) " & _
" WHEN 'T' THEN -1 * (ABS(QUANTITY) + ABS(FREE))WHEN 'Y' THEN ABS(QUANTITY) + ABS(FREE) END),PTY=SUM(CASE RET WHEN 'N' THEN -1 * (ABS(PQTY))" & _
" WHEN 'T' THEN -1 * (ABS(PQTY))WHEN 'Y' THEN ABS(PQTY) END) FROM SALES2,SALES1 WHERE SALES2.BILLNO=SALES1.BILLNO AND ITEMID='TIP91' " & _
" AND DATE <= '" & dtTo.Value & "' GROUP BY ITEMID UNION ALL SELECT ITEMID,QTY=SUM(CASE RET WHEN 'N' THEN -1 * (ABS(QUANTITY) + ABS(FREE)) " & _
" WHEN 'T' THEN -1 * (ABS(QUANTITY) + ABS(FREE))WHEN 'Y' THEN ABS(QUANTITY) + ABS(FREE) END),PTY=SUM(CASE RET WHEN 'N' THEN -1 * (ABS(PQTY)) " & _
" WHEN 'T' THEN -1 * (ABS(PQTY))WHEN " & _
" 'Y' THEN ABS(PQTY) END) FROM SALES8A2,SALES8A1 WHERE SALES8A2.BILLNO=SALES8A1.BILLNO AND ITEMID='TIP91' AND DATE <= '" & dtTo.Value & "' " & _
" GROUP BY ITEMID UNION ALL SELECT ITEMID,SUM (QUANTITY) AS QTY, SUM(PQTY) AS PTY FROM EditStock WHERE ITEMID='TIP91' AND " & _
" DATE <= '" & dtTo.Value & "' GROUP BY ITEMID UNION ALL SELECT ITEMID,QTY=SUM(CASE RET WHEN 'N' " & _
" THEN (ABS(QUANTITY)+ ABS(FREE)-ABS(QUANTITY*Wastage/100)) WHEN 'Y' THEN -1 * (ABS(QUANTITY)+ ABS(FREE)-ABS(QUANTITY*Wastage/100)) END), " & _
" PTY=SUM(CASE RET WHEN 'N' THEN ABS(PQTY) WHEN 'Y' THEN -1 *ABS(PQTY) END) FROM PURCHASE2,PURCHASE1 WHERE PURCHASE2.BILLNO=PURCHASE1.BILLNO AND " & _
" ITEMID='TIP91' AND DATE <= '" & dtTo.Value & "' GROUP BY ITEMID UNION ALL SELECT ITEMID, SUM (QUANTITY) AS QTY, SUM(PQTY) AS PTY FROM " & _
" SALESRETURN2,SALESRETURN1 WHERE SALESRETURN2.BILLNO=SALESRETURN1.BILLNO AND ITEMID='TIP91'AND DATE <= '" & dtTo.Value & "' GROUP BY ITEMID UNION ALL " & _
" SELECT ITEMID, SUM (-1 * QUANTITY) AS QTY, SUM(-1 * PQTY) AS PTY FROM PURCHASERETURN2,PURCHASERETURN1 WHERE " & _
" PURCHASERETURN2.BILLNO=PURCHASERETURN1.BILLNO AND ITEMID='TIP91' AND DATE <= '" & dtTo.Value & "' GROUP BY ITEMID UNION ALL SELECT ITEMID, " & _
" SUM (-1 * QUANTITY) AS QTY, SUM(-1 * PQTY) AS PTY FROM FREENOTE2,FREENOTE1 WHERE FREENOTE2.BILLNO=FREENOTE1.BILLNO AND ITEMID='" & rsRPTItem.Fields(0) & "' AND " & _
" DATE <= '" & dtTo.Value & "' GROUP BY ITEMID UNION ALL SELECT ITEMID, SUM (-1 * QUANTITY) AS QTY, SUM(-1 * PQTY) AS PTY FROM TRANSFER2, " & _
" TRANSFER1 WHERE TRANSFER2.BILLNO=TRANSFER1.BILLNO AND ITEMID='" & rsRPTItem.Fields(0) & "' AND DATE <= '" & dtTo.Value & "' GROUP BY ITEMID) AS MAINQRY, ITEMS WHERE ITEMS.ITEMID=MAINQRY.ITEMID GROUP BY ITEMS.ITEMID"