The image shows the actual error.I am using this following code for creating an audit trail in MS-access using vba script, but getting 3001 : Invalid argument error. I have already checked the table names field names etc. But couldn't solve the issue. Can someone please help?
I tried looking up the 3001 : invalid argument, but I can not determine exactly what is causing the problem in my scenario.
I would really appreciate it if anyone can help me out with this.
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
Thank you, Rito