总计匹配列表框选择
Posted
技术标签:
【中文标题】总计匹配列表框选择【英文标题】:Total to Match Listbox Selections 【发布时间】:2014-05-07 19:19:17 【问题描述】:我在表单上有一个列表框,用户手动选择包含单个数量的行,这些数量需要在选择这些记录之前添加到表单上输入的总数量。然后将选定的行发送到一个表格进行打印,以便正确更新实物库存。
我不确定如何在所选的总计高于指定的Quanitity时减去部分数量,并将差异发送到我的表格。我已经包含我的设置到目前为止...
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 and 5
和运输数量=8
,那么您希望在您的表格中看到数量2, 3 and 3
。这是正确的吗?
是的,这是正确的,但我昨晚解决了所有问题。现在我遇到了一个 DAO 对象的问题,它不想在特定表中查找和更新记录。
【参考方案1】:
这就是我想办法让它做我想让它做的事情......
Private Sub ctrSend_Click()
Dim intI As Integer
Dim lst As ListBox
Dim varItem As Variant
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim qtySum As Variant
Dim qtyDiff As Variant
Dim rowMax As Variant
Dim rowUpdate As Variant
Dim rowBIN As Variant
Dim sqlShip As String
Set lst = Me![lstShipping]
Set rst = CurrentDb.OpenRecordset("ShipInv", dbOpenTable)
Set rst2 = CurrentDb.OpenRecordset("Storage", dbOpenTable)
qtySum = 0
rowMax = 0
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, "Confirmation Message"
ElseIf Me.[ctrQtyProd] > qtySum Then
MsgBox "Qty Selected LESS THAN Qty Being Shipped, please select more Inventory.", vbOKOnly, "Confirmation Message"
Else
qtyDiff = qtySum - Me.[ctrQtyProd]
rowMax = lst.Column(3, lst.ItemsSelected.count)
rowUpdate = rowMax - qtyDiff
MsgBox "Qty Successfully Updated.", vbOKOnly, "Confirmation Message"
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 = rowUpdate
rst.Update
Next
End With
rst.Close
Set rst = Nothing
End Sub
【讨论】:
以上是关于总计匹配列表框选择的主要内容,如果未能解决你的问题,请参考以下文章