为什么会出现3022的运行时错误?

时间:2018-09-12 14:51:00

标签: ms-access

我遇到3022的运行时错误(索引中的值重复等),但是将数据添加到表中没有任何问题。

详细地,我单击“保存”按钮。数据已添加到表中,但是我仍然在rst.update上收到运行时错误。

Private Sub cmdSave_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("tblReload", dbOpenDynaset)

If IsNull(Me!txtReloadOrderNumber) Then
    MsgBox ("Please enter the PO Number.")
    Exit Sub
End If

If varFormNewEdit = False Then
    With rst
        .AddNew
        !ReloadDate = Me!txtReloadDate
        !ReloadRailroad = Me!txtReloadRailroad
        !ReloadOrderNumber = Me!txtReloadOrderNumber
        !ReloadOrderWeight = Me!txtReloadOrderWeight
        !ReloadDestination = Me!txtReloadDestination
        !ReloadCityState = Me!txtReloadCityState
    End With
Else
    With rst
        .FindFirst "[ReloadOrderNumber]=" & varReload
        .Edit
        !ReloadDate = Me!txtReloadDate
        !ReloadRailroad = Me!txtReloadRailroad
        !ReloadOrderNumber = Me!txtReloadOrderNumber
        !ReloadOrderWeight = Me!txtReloadOrderWeight
        !ReloadDestination = Me!txtReloadDestination
        !ReloadCityState = Me!txtReloadCityState
    End With
End If

rst.Update

1 个答案:

答案 0 :(得分:0)

我花了太多时间在这上面。我发布问题后,一个灯泡就熄灭了。我在两个事件过程(单击和输入)中编写了代码。

这很好,直到我关闭了“保存”按钮上的默认属性。因此,当我按下“保存”按钮上的Enter时,我同时触发了这两个事件,这就是为什么我会遇到运行时错误的原因。

谢谢!