0
我有一個窗體上的列表框,用戶在選擇這些記錄之前手動選擇包含需要添加到表單上輸入的總數量的單個數量的行。然後將選定的行發送到打印輸出表,以便正確更新實際庫存。總計到匹配列表框選擇
我不知道如何減去部分數量,當選擇的總數高於指定的數量並將差值發送到我的表格。我已經包括了我有什麼設置到目前爲止...
Private Sub ctrSend_Click()
Dim intI As Integer
Dim lst As ListBox
Dim varItem As Variant
Dim rst As DAO.Recordset
Dim qtySum As Variant
Dim qtyDiff As Variant
Dim rowMax As Variant
Dim rowUpdate As Variant
Set lst = Me![lstShipping]
Set rst = CurrentDb.OpenRecordset("ShipInv", dbOpenTable)
With lst
If .ItemsSelected.count = 0 Then Exit Sub
For Each varItem In .ItemsSelected
qtySum = qtySum + .Column(3, varItem)
Next
If Me.[ctrQtyProd] = qtySum Then
MsgBox "Qty Selected EQUALS Qty Being Shipped.", vbOKOnly, "Quantity Confirmation"
ElseIf Me.[ctrQtyProd] > qtySum Then
MsgBox "Qty Selected LESS THAN Qty Being Shipped, please select more Inventory.", vbOKOnly, "Inventory Confirmation"
Else Me.[ctrQtyProd] < qtySum Then
qtyDiff = qtySum - Me.[ctrQtyProd]
.Column(3, .ItemSelected.count - 1) = .Column(3, .ItemSelected.count - 1) - qtyDiff
End If
End With
With lst
For Each varItem In .ItemsSelected
rst.AddNew
rst!Order = Me.[ctrSOrder]
rst!EntDate = Date
rst!ShipDate = Me.[ctrSDate]
rst!BIN = .Column(0, varItem)
rst!SKU = .Column(1, varItem)
rst!Lot = .Column(2, varItem)
rst!QtyProd = .Column(3, varItem)
rst.Update
Next
End With
rst.Close
Set rst = Nothing
MsgBox "Warehouse Inventory Updated", vbOKOnly, "Update Confirmation"
End Sub
您可以擴展問題與一個小例子?我在更正目標時正確如下:**如果qtySum> ctrQtyProd然後減去列表中最後一個選定數量的差異**?因此,如果我在列表中選擇數量「2,3和5」並且運輸數量=「8」,那麼在您的表格中您想要查看數量「2,3和3」。它是否正確? – Yoh
是的,這是正確的,但我昨天晚上都解決了。現在我遇到了DAO對象的問題,它不想在特定的表中查找和更新記錄。 –