简体   繁体   中英

VBA type mismatch in Access

Good afternoon all

I'm attmepting to implement an audit trail for a small database here at work and I've borrowed my code from Martin Greens' Fontstuff website Martin Green's Audit trail

so I have a code module that constist of

Sub AuditChanges(IDField As String)
On Error GoTo AuditChanges_Err

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim ctl As Control
Dim datTimeCheck As Date
Dim strUserID As String
Dim strReason As String
Dim strName As String

Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM tblAuditTrail", cnn, adOpenDynamic, adLockOptimistic
datTimeCheck = Now()
strUserID = Environ("USERNAME")

strReason = InputBox("Enter Reason", "Reason")
'strName = InputBox("Enter Name", "Name")

For Each ctl In Screen.ActiveForm.Controls
    If ctl.Tag = "Audit" Then
        If Nz(ctl.Value) <> Nz(ctl.OldValue) Then
            With rst
                .AddNew
                ![DateTime] = datTimeCheck
                ![UserName] = strUserID
                ![FormName] = Screen.ActiveForm.Name
                ![RecordID] = Screen.ActiveForm.Controls(IDField).Value
                ![FieldName] = ctl.ControlSource
                ![OldValue] = ctl.OldValue
                ![NewValue] = ctl.Value
                ![Reason] = strReason
                ![Name] = CurrentUser()
                .Update
            End With
        End If
    End If
Next ctl

AuditChanges_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub

AuditChanges_Err:
MsgBox Err.Description, vbCritical, "ERROR!"
Resume AuditChanges_Exit
End Sub

and a short line in the before update method of each control on a form as follows

If Not Me.NewRecord Then Call AuditChanges("ID")

My problem being if I run the database on a windows 7 machine everything works as it should.

We do however have a few XP machines on which the dB has to be accessed and for some reason I get a type mismatch error when the code is executed unfortunately I'm unable to access these machines easily as they are on a different site

Any Ideas?

Thanks

This is the consolidation of all the comments into answer.

Check the ADO version of the remote machines. Windows 7 where you're developing has access to later version than an XP machine would. https://msdn.microsoft.com/en-us/library/windows/desktop/ms676506%28v=vs.85%29.aspx


From HansUp You can ask the remote user to run this as a single line in the Access Immediate window:

 for i = 1 to references.count : ? references(i).Name, references(i).Major, references(i).Minor, references(i).IsBroken : next

If nothing shows True for IsBroken, the library versions are not the cause of your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM