我有一个更新材料记录的流程。但首先它会在更新之前以及当我尝试使用新的更新时获取材料的现有记录,例如可用数量。我收到错误说“运行时错误'-2147217864(80040e38)':无法找到行进行更新。某些值可能自上次读取后已更改。”
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
Dim coy As String
If Left(Text4.Text, 3) = "800" Then
For i = 1 To ListView2.ListItems.Count
With ListView2.ListItems(i)
If rs.State <> 0 Then rs.Close
rs.Open "Select * from Inventory where InventoryID = " & Val(.ListSubItems(6).Text), db, 3, 3
If rs.RecordCount <> 0 Then
'get average cost start
Dim avgcost, Stockqty, newstockqty As Double
Stockqty = CDbl(rs!AvailQty) * CDbl(rs!unitprice)
newstockqty = CDbl(.ListSubItems(7).Text) * CDbl(.ListSubItems(8).Text)
avgcost = (Stockqty + newstockqty) / CDbl(CDbl(rs!AvailQty) +
CDbl(.ListSubItems(7).Text))
'get average cost end
rs!avecost = FormatNumber(avgcost, 3)
avaiqtyparam = CDbl(rs!AvailQty) + CDbl(.ListSubItems(7).Text)
rs!AvailQty = CDbl(rs!AvailQty) + CDbl(.ListSubItems(7).Text)
rs!unitprice = FormatNumber(CDbl(.ListSubItems(8).Text), 5)
rs!lastupdate = FormatDateTime(DTPicker1.Value, vbShortDate)
Dim AvgVat, stockvat, nestockvat As Double
stockvat = CDbl(rs!AvailQty) * CDbl(rs!AvailVAT)
nestockvat = CDbl(.ListSubItems(7).Text) * CDbl(.ListSubItems(11).Text)
AvgVat = (stockvat + nestockvat) / CDbl(CDbl(rs!AvailQty) +
CDbl(.ListSubItems(11).Text))
rs!AvailVAT = CDbl(.ListSubItems(11).Text)
rs!AveVAT = FormatNumber(AvgVat, 3)
rs.Update
End If
End With
rs.Close
Set rs = Nothing
Next i