L
Lez
I have re worked this code and cannot understand why it only updates the
first record? If anyone could take a read through and hopefully pickup what
I am missing it would be most apreciated.
The premis it to recceive new stock in and update if the stock exists or add
if not. The code works in as much as the first item on an order is added or
updated, but no other items on an order is included?
Code:
Private Sub cmdClose_Click()
Dim strSQlCS As String
Dim strSQlGIL As String
Me.goodsintotal = Me.frmGoodsSub!txtGross
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Set rsgoodsinlineitems = CurrentDb.OpenRecordset("tblGoodsInLineItems",
dbOpenDynaset)
Set rsinventory = CurrentDb.OpenRecordset("tblinventory", dbOpenDynaset)
Set rsinventorydetail = CurrentDb.OpenRecordset("tblinventorydetail",
dbOpenDynaset)
strSQlGIL = "INSERT INTO tblinventoryDetail ( qty" & vbCrLf
strSQlGIL = strSQlGIL & " , productID" & vbCrLf
strSQlGIL = strSQlGIL & " , cost" & vbCrLf
strSQlGIL = strSQlGIL & " , unitsID" & vbCrLf
strSQlGIL = strSQlGIL & " , name" & vbCrLf
strSQlGIL = strSQlGIL & " , rrp" & vbCrLf
strSQlGIL = strSQlGIL & " , Code" & vbCrLf
strSQlGIL = strSQlGIL & " , workingprice )SELECT
tblGoodsinlineitems.qty" & vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.productID"
& vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.cost" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.unitsID" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.name" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.rrp" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.Code" &
vbCrLf
strSQlGIL = strSQlGIL & " ,
tblgoodsinLineitems.workingprice" & vbCrLf
strSQlGIL = strSQlGIL & " FROM tblgoodsinlineitems" & vbCrLf
strSQlGIL = strSQlGIL & " WHERE
(((tblgoodsinlineitems.stockinID)=[forms]![frmGoodsReceipt]![txtStockinID]));"
strSQlCS = "UPDATE tblinventory " & vbCrLf
strSQlCS = strSQlCS & " INNER JOIN tblinventorydetail " & vbCrLf
strSQlCS = strSQlCS & " ON tblinventory.productID =
tblinventorydetail.productID SET tblinventory.Sumofqty =
[tblinventory]![SumOfqty]+[tblinventorydetail]![qty]" & vbCrLf
strSQlCS = strSQlCS & " WHERE
(((tblinventorydetail.productID)=[tblinventory]![ProductID]) " & vbCrLf
strSQlCS = strSQlCS & " AND
((tblinventorydetail.name)=[tblinventory]![name]));"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQlGIL
DoEvents
Set rsinventorydetail =
CurrentDb.OpenRecordset("tblinventorydetail", dbOpenDynaset)
If rsinventory.RecordCount > 0 Then
rsinventory.FindFirst "[ProductID]=" &
rsinventorydetail![productID]
If rsinventory.NoMatch = False Then
DoCmd.RunSQL strSQlCS
ElseIf rsinventory.NoMatch = True Then
DoCmd.OpenQuery "qryTemp", acViewNormal
End If
End If
If rsinventory.RecordCount = 0 Then
DoCmd.OpenQuery "qryTemp", acViewNormal
End If
DoCmd.OpenQuery "qryDeltblCSDetail"
rsgoodsinlineitems.Close
rsinventory.Close
rsinventorydetail.Close
Set rsinventory = Nothing
Set rsinventorydetail = Nothing
Set rsgoodsinlineitems = Nothing
DoCmd.Close
End Sub
TIA
first record? If anyone could take a read through and hopefully pickup what
I am missing it would be most apreciated.
The premis it to recceive new stock in and update if the stock exists or add
if not. The code works in as much as the first item on an order is added or
updated, but no other items on an order is included?
Code:
Private Sub cmdClose_Click()
Dim strSQlCS As String
Dim strSQlGIL As String
Me.goodsintotal = Me.frmGoodsSub!txtGross
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Set rsgoodsinlineitems = CurrentDb.OpenRecordset("tblGoodsInLineItems",
dbOpenDynaset)
Set rsinventory = CurrentDb.OpenRecordset("tblinventory", dbOpenDynaset)
Set rsinventorydetail = CurrentDb.OpenRecordset("tblinventorydetail",
dbOpenDynaset)
strSQlGIL = "INSERT INTO tblinventoryDetail ( qty" & vbCrLf
strSQlGIL = strSQlGIL & " , productID" & vbCrLf
strSQlGIL = strSQlGIL & " , cost" & vbCrLf
strSQlGIL = strSQlGIL & " , unitsID" & vbCrLf
strSQlGIL = strSQlGIL & " , name" & vbCrLf
strSQlGIL = strSQlGIL & " , rrp" & vbCrLf
strSQlGIL = strSQlGIL & " , Code" & vbCrLf
strSQlGIL = strSQlGIL & " , workingprice )SELECT
tblGoodsinlineitems.qty" & vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.productID"
& vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.cost" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.unitsID" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.name" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.rrp" &
vbCrLf
strSQlGIL = strSQlGIL & " , tblgoodsinLineitems.Code" &
vbCrLf
strSQlGIL = strSQlGIL & " ,
tblgoodsinLineitems.workingprice" & vbCrLf
strSQlGIL = strSQlGIL & " FROM tblgoodsinlineitems" & vbCrLf
strSQlGIL = strSQlGIL & " WHERE
(((tblgoodsinlineitems.stockinID)=[forms]![frmGoodsReceipt]![txtStockinID]));"
strSQlCS = "UPDATE tblinventory " & vbCrLf
strSQlCS = strSQlCS & " INNER JOIN tblinventorydetail " & vbCrLf
strSQlCS = strSQlCS & " ON tblinventory.productID =
tblinventorydetail.productID SET tblinventory.Sumofqty =
[tblinventory]![SumOfqty]+[tblinventorydetail]![qty]" & vbCrLf
strSQlCS = strSQlCS & " WHERE
(((tblinventorydetail.productID)=[tblinventory]![ProductID]) " & vbCrLf
strSQlCS = strSQlCS & " AND
((tblinventorydetail.name)=[tblinventory]![name]));"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQlGIL
DoEvents
Set rsinventorydetail =
CurrentDb.OpenRecordset("tblinventorydetail", dbOpenDynaset)
If rsinventory.RecordCount > 0 Then
rsinventory.FindFirst "[ProductID]=" &
rsinventorydetail![productID]
If rsinventory.NoMatch = False Then
DoCmd.RunSQL strSQlCS
ElseIf rsinventory.NoMatch = True Then
DoCmd.OpenQuery "qryTemp", acViewNormal
End If
End If
If rsinventory.RecordCount = 0 Then
DoCmd.OpenQuery "qryTemp", acViewNormal
End If
DoCmd.OpenQuery "qryDeltblCSDetail"
rsgoodsinlineitems.Close
rsinventory.Close
rsinventorydetail.Close
Set rsinventory = Nothing
Set rsinventorydetail = Nothing
Set rsgoodsinlineitems = Nothing
DoCmd.Close
End Sub
TIA