I have created an action query which is working ok in MS Access, now I want to convert it to a Passthrough query, though at first was looking like easy but the trouble came in because of the date and form input values which are mandatory. Below is a query in Ms Access and finally the modified into a passthrough query which is not working:
Ms Access working query
Pass Through query Modified
The problem here is how to handle the Date() As mth and [Forms]![frmGrn]![GRNID] AS DocID , I'm complete stuck here
Required ideal move or final pass through query
Ms Access working query
Code:
INSERT INTO tblGrnDetails ( Warehouse, ProductID, Qty, Cost, GRNID, GrnStockAccName, GrnStockAcc, SuspenseName, SuspenseAcc, BSIDSTOCK, BSIDSuspense, GrnDate, Discounts, Vat, PurchasesDate, PurchaseOrderID )
SELECT tblPurchasesDetailslines.Warehouse, tblProducts.ProductID, tblPurchasesDetailslines.Quantity, tblPurchasesDetailslines.CostValue, [Forms]![frmGrn]![GRNID] AS DocID, "Stock" AS GrnstockName, "114-10-1000" AS GrnStockAccount, "GRN Suspense" AS GrnSuspenseName, "121-12-1000" AS GRNSuspenseAccount, "2" AS BSIDStock, "3" AS BSIDSuspense, Date() AS Mth, tblPurchasesDetailslines.Discounts, tblPurchasesDetailslines.Vat, tblPurchasesHeader.PurchasesDate, tblPurchasesHeader.PurchaseID
FROM tblPurchasesHeader INNER JOIN (tblWarehouse INNER JOIN (tblProducts INNER JOIN tblPurchasesDetailslines ON tblProducts.ProductID = tblPurchasesDetailslines.ProductID) ON tblWarehouse.WHID = tblProducts.WHID) ON tblPurchasesHeader.PurchaseID = tblPurchasesDetailslines.PurchaseID
WHERE (((tblPurchasesDetailslines.PurchaseID)=[Forms]![frmGrn]![CboOrder]));
Pass Through query Modified
Code:
INSERT INTO tblGrnDetails ( Warehouse, ProductID, Qty, Cost, GRNID, GrnStockAccName, GrnStockAcc, SuspenseName, SuspenseAcc, BSIDSTOCK, BSIDSuspense, GrnDate, Discounts, Vat, PurchasesDate, PurchaseOrderID )
SELECT tblPurchasesDetailslines.Warehouse, tblProducts.ProductID, tblPurchasesDetailslines.Quantity, tblPurchasesDetailslines.CostValue, [Forms]![frmGrn]![GRNID] AS DocID, 'Stock' AS GrnstockName, '114-10-1000' AS GrnStockAccount, 'GRN Suspense' AS GrnSuspenseName, '121-12-1000' AS GRNSuspenseAccount, '2' AS BSIDStock, '3' AS BSIDSuspense, Date() AS Mth, tblPurchasesDetailslines.Discounts, tblPurchasesDetailslines.Vat, tblPurchasesHeader.PurchasesDate, tblPurchasesHeader.PurchaseID
FROM tblPurchasesHeader INNER JOIN (tblWarehouse INNER JOIN (tblProducts INNER JOIN tblPurchasesDetailslines ON tblProducts.ProductID = tblPurchasesDetailslines.ProductID) ON tblWarehouse.WHID = tblProducts.WHID) ON tblPurchasesHeader.PurchaseID = tblPurchasesDetailslines.PurchaseID
The problem here is how to handle the Date() As mth and [Forms]![frmGrn]![GRNID] AS DocID , I'm complete stuck here
Required ideal move or final pass through query
Code:
On Error GoTo Err_Handler
Dim db As DAO.Database
Dim strSql As String
Set db = CurrentDb
strSql = "SELECT * FROM [PassThrough Qry] WHERE [tblPurchasesDetailslines.PurchaseID] = " & [Forms]![frmGrn]![CboOrder]
DoCmd.SetWarnings False
DoCmd.OpenQuery "PassThrough Qry"