1

图像显示了实际错误。我正在使用以下代码在 MS-access 中使用 vba 脚本创建审计跟踪,但得到 3001 : Invalid argument 错误。我已经检查了表名字段名等。但无法解决问题。有人可以帮忙吗?

我尝试查找 3001 : invalid 参数,但我无法确定在我的场景中导致问题的确切原因。

如果有人能帮助我解决这个问题,我将不胜感激。

Public Function AuditChanges(RecordID As String, UserAction As String)
On Error GoTo auditerr

Dim DB As Database
Dim rst As Recordset
Dim clt As Control
Dim UserLogin As String

Set DB = CurrentDb
Set rst = DB.OpenRecordset("select * from audit", adOpenDynamic)

UserLogin = Environ("UserName")
Select Case UserAction
    Case "new"
        With rst
            .AddNew
            ![DateTime] = Now()
            !UserName = UserLogin
            !FormName = ScreenActiveForm.Name
            !Action = UserAction
            !RecordID = Screen.ActiveForm.Controls(RecordID).Value
            .Update

         End With

    Case "Delete"
        With rst
            .AddNew
            ![DateTime] = Now()
            !UserName = UserLogin
            !FormName = ScreenActiveForm.Name
            !Action = UserAction
            !RecordID = Screen.ActiveForm.Controls(RecordID).Value
            .Update

        End With

    Case "Edit"
        For Each clt In Screen.ActiveForm.Controls
            If (clt.ControlType = acTextBox _
                Or clt.ControlType = acComboBox) Then
                If Nz(clt.Value) <> Nz(clt.OldValue) Then
                With rst
                    .AddNew
                    ![DateTime] = Now()
                    !UserName = UserLogin
                    !FormName = ScreenActiveForm.Name
                    !Action = UserAction
                    !RecordID = Screen.ActiveForm.Controls(RecordID).Value
                    !FieldName = clt.ControlSource
                    !OldValue = clt.OldValue
                    !newvalue = clt.Value
                    .Update
                End With
            End If
        End If

    Next clt

End Select

rst.Close
DB.Close
Set rst = Nothing
Set DB = Nothing
auditerr:
MsgBox Err.Number & " : " & Err.Description, vbCritical, "Error"
Exit Function

End Function  

谢谢你,里托

4

1 回答 1

0

尝试这个

Set rst = DB.OpenRecordset("select * from audit", dbOpenDynaset)

于 2018-09-06T20:36:56.143 回答