Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    AccessRockie is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2019
    Posts
    11

    Error 3001: Invalid Argument

    Greetings Fellow Access users,

    I'm working on an MS Access document that requires an audit trail. When I save/update data or add new data on the required form I receive an error '3001: Invalid Argument'
    However VBA does not come up with any debug issues. That data saves in the required table however nothing is inputted the audit trail table......
    I'm out of ideas on how to fix this.

    Thanks in advanced


    Here is the code I'm using in the form:

    Private Sub Form_BeforeUpdate(Cancel As Integer)

    If Me.NewRecord Then
    Call AuditChanges("Book_ID", "New")

    Else
    Call AuditChanges("Book_ID", "Edit")

    End If


    End Sub

    -------------------------------------------------------------------------------------------------

    Here is the Code in the Module section if it helps:

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

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

    Set DB = CurrentDb
    Set rst = DB.OpenRecordset("SELECT * from tbl_AuditTrail", 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 "Edit"
    For Each ctl In Screen.ActiveForm.Controls
    If (ctl.Control = acTextBox _
    Or ctl.Control = acComboBox) Then

    If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
    With rst
    .AddNew
    ' !DateTime = Now()
    !UserName = UserLogin
    !FormName = Screen.ActiveForm.Name
    !Action = UserAction
    !RecordID = Screen.ActiveForm.Controls(RecordID).Value
    !FieldName = ctl.ControlSource
    !OldValue = ctl.OldValue
    !NewValue = ctl.Value
    .Update


    End With

    End If
    End If
    Next ctl

    End Select

    rst.Close
    DB.Close
    Set rst = Nothing
    Set DB = Nothing

    auditerr:
    MsgBox Err.Number & " : " & Err.Description, vbCritical, "Error"
    Exit Function

    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Temporarily comment out the On Error... line and run the code. You should be able to find out what line throws the error.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I had an inkling, which with more consideration, I found faulty, so deleted it here.
    I second Paul's suggestion to narrow the error to a line of code.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Is RecordID actually defined as Text...or is it a Number, as is usually the case?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    The value of RecordID is being used in the function as the name of a control. So if the active form has no control named BOOK_ID, thus the error.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If RecordID is the name of the control, it has to be within quotes when using the controls collection syntax (unless the word is a variable and I missed that).
    e.g. .Controls("RecordID")
    Also, ctl has been declared as a Control, so ctl.Control is the same as saying Control.Control I think the intention is ctl.ControlType (in the controls loop).
    Last edited by Micron; 11-22-2019 at 09:26 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You missed it, but your second point is valid. I was trying to teach how to fish.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    OK all yours - again.

  9. #9
    AccessRockie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2019
    Posts
    11
    Quote Originally Posted by pbaldy View Post
    Temporarily comment out the On Error... line and run the code. You should be able to find out what line throws the error.

    Ok Thanks for that. I tcommented out the error and the debugging highlighted code below:


    Set rst = DB.OpenRecordset("SELECT * from tbl_audittrail", adOpenDynamic)


    There is no issues with the table name...everything else... I'm unsure of here....

  10. #10
    AccessRockie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2019
    Posts
    11
    Good point Missingling. It's listed as a number.

  11. #11
    AccessRockie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2019
    Posts
    11
    Quote Originally Posted by Micron View Post
    If RecordID is the name of the control, it has to be within quotes when using the controls collection syntax (unless the word is a variable and I missed that).
    e.g. .Controls("RecordID")
    Also, ctl has been declared as a Control, so ctl.Control is the same as saying Control.Control I think the intention is ctl.ControlType (in the controls loop).

    Good point again. I did originally have it as 'ControlType', not sure why I took it out.
    I have tried with "RecordID" and states that it can't find the field all though I'm looking at it in the table. Iplayed around with it and I THINK I overcome thta problem.
    But now there is an error with the .Update feature stating
    Error: 3058 Primary key cannot contain a Null value.

    MY HEAD HURTS

  12. #12
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Quote Originally Posted by AccessRockie View Post
    Error: 3058 Primary key cannot contain a Null value.
    If the primary key is an autonumber it will be created automatically with each new record. If not, you will need to supply the primary key value yourself. Easiest way, of course, use an autonumber.

  13. #13
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by AccessRockie View Post
    Good point Missingling. It's listed as a number.
    Thought so...But your Function is asking for a String:

    Public Function AuditChanges(RecordID As String, UserAction As String)

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  14. #14
    AccessRockie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2019
    Posts
    11
    Quote Originally Posted by davegri View Post
    If the primary key is an autonumber it will be created automatically with each new record. If not, you will need to supply the primary key value yourself. Easiest way, of course, use an autonumber.
    Yeah the primary key in both tables (the audit table and main table) are both autonumbers.... this is what I can't understand.

  15. #15
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    eah the primary key in both tables (the audit table and main table) are both autonumbers.... this is what I can't understand.
    I think you need to attach your DB here at the forum for us to have a look.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Runtime Error 3001: Invalid Argument
    By VAer in forum Access
    Replies: 4
    Last Post: 08-30-2018, 04:12 PM
  2. Replies: 2
    Last Post: 02-09-2017, 05:22 AM
  3. Invalid Argument Error Message
    By kcochran130 in forum General Chat
    Replies: 1
    Last Post: 05-30-2013, 08:20 AM
  4. Replies: 8
    Last Post: 06-18-2012, 03:49 PM
  5. Invalid Argument Error
    By koper in forum Access
    Replies: 2
    Last Post: 06-14-2010, 11:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums