AfterUpdate 组合框查找和替换

AfterUpdate combobox find and replace

我想弄清楚如何在组合框上使用 AfterUpdate 让它从 table "Userdata" 中找到记录,其中字段 "Recall_position" 等于“1”并替换它与“0”。

然后找到在组合框中选择的记录(已更新到)并在 "Recall_position" 下的 "Userdata" 中输入数字“1”

像这样?

Private Sub cmbTest_AfterUpdate()

    CurrentDb.Execute "update Userdata set Recall_position = 0 where Recall_position = 1"
    CurrentDb.Execute "update Userdata set Recall_position = 1 where ID = " & Me.cmbTest.Column(0)

End Sub

第一个查询将所有包含 Recall_position = 1 的记录更新为 Recall_position = 0

第二个查询将组合框中所选项目第一列中ID为Recall_position = 1的记录更新为Recall_position = 1
(我假设它是一个数值并且 table 中的列称为 ID

所以使用我的代码

Private Sub Combo1_AfterUpdate()
    CurrentDb.Execute "UPDATE Userdata SET Recall_position = 0 WHERE Recall_position = 10"
CurrentDb.Execute "UPDATE Userdata SET Recall_position = 10 WHERE Lastname = '" & Me.Combo1.Column(1)  & "'"
End Sub

它清除了 10 并将右行更新为 10也一样。但是,它还在 Lastname

中使用随机数更新第二行