图像显示了实际错误。我使用以下代码使用 vba 脚本在 MS 访问中创建审计跟踪,但得到 3001:无效参数错误。我已经检查了表名字段名称等。但无法解决问题。 有人可以帮忙吗?
我尝试查找 3001 : 无效参数,但我无法准确确定在我的场景中导致问题的原因。
如果有人能帮助我解决这个问题,我将不胜感激。
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
谢谢 里托
试试这个
Set rst = DB.OpenRecordset("select * from audit", dbOpenDynaset)