
[英]How can I edit/update an existing record in my database using a listbox in Excel userform?
[英]Select one record from Userform listbox with same ID, and only edit values in selected record
我的工作簿已完成 95%,但遇到了新问题。 情况截图: https : //ibb.co/Z6dZN18
介绍:我有用户表单,用于列表框这样的情况,当我在 Txtbox7 标签 ID 中输入 ID 进行搜索时,搜索结果显示在列表框中。
接下来,当我 dbl_click 所需的搜索结果时,我会填充相应的文本框。 例如,当我发行部分 ID 为 35 的产品时会出现问题。 在股票上,我有 500 件该产品(ID 35),我需要提供 300 件。 当我在第二个工作表“Izdato”中生成新的转移记录时,我的产品 ID 为 35,有 300 个单位,而在第一个工作表“RM”ID 35 中有 200 个单位(500-300=200)。
几天后,当我给他们剩余的 200 个单位时,我将在“Izdato”表上创建一个新记录,ID 为 35,因为它是相同的产品,我无法在相同(行)记录中对这些数量求和,因为转移历史记录,这就像预期的那样。
我的问题来了,有时我需要将已发行的金额从“Izdato”表返回到“RM”表,当我 dbl_click 列表框中的记录时,我想返回并将数量设置为 0(零),因为它已返回。 Excel 更改具有相同 ID 的所有记录的数量值,我只想更改选定的记录。
在上面的屏幕截图链接中,在橙色填充的行中,我想将数量设置为零,因为它将 200 个单位返回到存储。 当我通过用户表单执行此操作时,我更改了绿色填充行中的值,因为它具有相同的 ID,我不希望这种情况发生。
有没有办法在不更改身份证号码的情况下防止这种情况发生? 如果有任何好处,我会使用此代码在列表框中搜索和显示数据:
Private Sub CommandButton8_Click()
Dim sh As Worksheet
Set sh = Sheets("Izdato")
Dim i As Long
Dim x As Long
Dim p As Long
Me.ListBox1.Clear
'code for header
Me.ListBox1.AddItem "ID"
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = "Box number"
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = "Name"
Me.ListBox1.List(ListBox1.ListCount - 1, 3) = "Quantiy"
Me.ListBox1.List(ListBox1.ListCount - 1, 4) = "Measurment"
Me.ListBox1.List(ListBox1.ListCount - 1, 5) = "Status"
Me.ListBox1.List(ListBox1.ListCount - 1, 6) = "Date of return"
Me.ListBox1.List(ListBox1.ListCount - 1, 7) = "Note"
For i = 1 To sh.Range("A" & Rows.Count).End(xlUp).Row
For x = 1 To Len(sh.Cells(i, 1))
p = Me.TextBox7.TextLength
If LCase(Mid(sh.Cells(i, 1), x, p)) = Me.TextBox7 And Me.TextBox7 <>
""Then
With Me.ListBox1
.AddItem sh.Cells(i, 1)
.List(ListBox1.ListCount - 1, 1) = sh.Cells(i, 2)
.List(ListBox1.ListCount - 1, 2) = sh.Cells(i, 3)
.List(ListBox1.ListCount - 1, 3) = sh.Cells(i, 4)
.List(ListBox1.ListCount - 1, 4) = sh.Cells(i, 5)
.List(ListBox1.ListCount - 1, 5) = sh.Cells(i, 10)
.List(ListBox1.ListCount - 1, 7) = sh.Cells(i, 13)
.List(ListBox1.ListCount - 1, 6) = sh.Cells(i, 9)
End With
End If
Next x
Next i
End Sub
再次,提前致谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.