Access中的VBA类型不匹配

时间:2015-03-25 13:52:32

标签: vba windows-7 access-vba windows-xp mismatch

下午好,

我正在努力在工作中为小型数据库实施审计跟踪,我从Martin Greens的Fontstuff网站借用了我的代码 Martin Green's Audit trail

所以我有一个

的常量代码模块
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

和表单上每个控件的更新前方法中的一个短行如下

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

我的问题是,如果我在Windows 7机器上运行数据库,一切正常。

然而,我们确实有一些必须访问dB的XP机器,并且由于某种原因,我在执行代码时遇到类型不匹配错误,遗憾的是我无法轻松访问这些机器,因为它们处于不同的状态网站

任何想法?

谢谢

1 个答案:

答案 0 :(得分:0)

这是将所有评论合并为答案。

检查远程计算机的ADO版本。您正在开发的Windows 7可以访问比XP机器更高版本的版本。 https://msdn.microsoft.com/en-us/library/windows/desktop/ms676506%28v=vs.85%29.aspx

<小时/> 来自HansUp 您可以要求远程用户在Access Immediate窗口中将其作为单行运行:

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

如果IsBroken没有显示True,则库版本不是您问题的原因。