Results 1 to 4 of 4
  1. #1
    vad77 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2013
    Location
    USA
    Posts
    105

    Question VBA error - ByRef argument type mismatch -Audit

    I am currently working on a database and I am at the point where I add my auditing code to track edits, adds and deletes. I found this code many years ago on this forum and I have been using it for all my databases. There is a module built with the code that performs the function of tracking. The After Update, Before Update, Delete and After Delete Confirm functions of a form are set with the following code.


    I getting the error at the BeforeUpdate function.

    Main table: tbl_ManagedIP
    Audit Temp: audTmpManagedIP
    Audit table: audManagedIP
    Primary key: PhnIndex

    Code:
    Private SubForm_AfterDelConfirm(status As Integer)CallAuditDelEnd("audTmpManagedIP", "audManagedIP", status)
    End Sub
    
    Private SubForm_AfterUpdate()
    CallAuditEditEnd("tbl_ManagedIP", "audTmpManagedIP","audManagedIP", "phnindex", Nz(Me!phnindex, 0),bWasNewRecord)
    End Sub
    
    Private SubForm_BeforeUpdate(Cancel As Integer)
    bWasNewRecord =Me.NewRecord
    CallAuditEditBegin("tbl_managedip", "audTmpManagedip","phnindex", Nz(Me.phnindex, 0), bWasNewRecord)
    End Sub
    
    Private SubForm_Delete(Cancel As Integer)
    CallAuditDelBegin("tbl_managedip", "audTmpmanagedip","phnindex", Nz(Me.phnindex, 0))
    End Sub
    Click image for larger version. 

Name:	AuditTrailerror.PNG 
Views:	9 
Size:	33.3 KB 
ID:	33423

    I am including a screenshot of the error. In the past I have never gotten this type of error before. I am currently on Office365 ProPlus.

    Any help on this error would be greatly appreciated.

    Vito

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you did not show us AuditEditBegin()
    that parameter setting.
    Im guessing it is boolean, so is it defined as such?

  3. #3
    vad77 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2013
    Location
    USA
    Posts
    105
    Ranman, the code from the module is below. Thanks for you reply.



    Code:
    Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _    lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
    'On Error GoTo Err_AuditEditBegin
        'Purpose:    Write a copy of the old values to temp table.
        '            It is then copied to the true audit table in AuditEditEnd.
        'Arugments:  sTable = name of table being audited.
        '            sAudTmpTable = name of the temp audit table.
        '            sKeyField = name of the AutoNumber field.
        '            lngKeyValue = Value of the AutoNumber field.
        '            bWasNewRecord = True if this was a new insert.
        'Return:     True if successful
        'Usage:      Called in form's BeforeUpdate event. Example:
        '                bWasNewRecord = Me.NewRecord
        '                Call AuditEditBegin("tblInvoice", "audTmpInvoice", "InvoiceID", Me.InvoiceID, bWasNewRecord)
        Dim db As DAO.Database           ' Current database
        Dim sSQL As String
    
    
        'Remove any cancelled update still in the tmp table.
        Set db = DBEngine(0)(0)
        sSQL = "DELETE FROM " & sAudTmpTable & ";"
        db.Execute sSQL
    
    
        ' If this was not a new record, save the old values.
        If Not bWasNewRecord Then
            sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser ) " & _
                "SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, " & sTable & ".* " & _
                "FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
            db.Execute sSQL, dbFailOnError
        End If
        AuditEditBegin = True
    
    
    Exit_AuditEditBegin:
        Set db = Nothing
        Exit Function
    
    
    
    
    End Function

  4. #4
    vad77 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2013
    Location
    USA
    Posts
    105
    Ranman, thanks for pointing me in the right direction. It seems I placed the following statement in the wrong place, "Dim bWasNewRecord As Boolean".

    Thanks again.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Referencing an Accde and getting ByRef Mismatch
    By Perceptus in forum Programming
    Replies: 5
    Last Post: 10-01-2015, 01:49 PM
  2. Audit Trail Code Type Mismatch
    By sstiebinger in forum Programming
    Replies: 9
    Last Post: 04-03-2015, 08:59 AM
  3. Another ByRef type mismatch
    By Levonas in forum Programming
    Replies: 3
    Last Post: 03-05-2015, 03:06 PM
  4. Compile Error: ByRef argument type mismatch
    By gaker10 in forum Programming
    Replies: 3
    Last Post: 11-17-2014, 10:33 AM
  5. byref argument type mismatch error
    By karuppasamy in forum Access
    Replies: 1
    Last Post: 06-22-2011, 09:37 AM

Tags for this Thread

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