I have this problem in access VBA, it keep giving me error 3001: invalid argument. I'm new to this language and couldn't find where is my mistake or any other solution online.

I'd really love the help.

I tried to use DAO but it gives me the "NAme conflicts with existing module..." error

      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 tbl_TRACKMP", adOpenDynamic)

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

         End With

    Case "Delete"
        With rst
            .AddNew
            ![DateTime] = Now()
            !UserName = UserLogin
            !FormName = Screen.ActiveForm.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 = Screen.ActiveForm.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

0 Answers