The image shows the actual error.我正在使用以下代码在使用vba脚本的MS-access中创建审核跟踪,但得到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
谢谢你, 里托(Rito)
答案 0 :(得分:0)
尝试一下
Set rst = DB.OpenRecordset("select * from audit", dbOpenDynaset)