Table update Help

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 would be most apreciated.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

table update help 0
join expression not supported 3
Update Error 5
Help...'Variable Not Defined' 3
CODE HELP! 2
Loop Help 4
Help with Loop 1
Update query using Count 4

Top