Access 2010 Recordset Ms在某些计算机上不会绑定到组合框

时间:2014-05-23 12:59:29

标签: vba ms-access-2007 ms-access-2010 ado dao

我有一个访问2010数据库,它是一个访问2007数据库。它在网络服务器上使用第二个数据库。

我正在开发Windows 7 32位。

以下是我继承的代码......

我遇到的问题是,虽然数据集绑定到组合框(Combo96)对于我来说在“开发模式”和“运行模式”中都很好,但它也适用于另一台Windows 7 32位机器和另一台Windows 7 64位机器。它拒绝在一台32位机器上工作。

我猜测引用存在问题?我所知道的目标(失败)机器是Windows 7,它具有访问2010运行时,它可能有访问2007或访问2007运行时,我真的没有办法找到。

我在底部添加了代码,该代码获取数据集并将其复制到组合框中。这适用于所有机器,但需要相当长的时间。

为什么数据集不会在某些机器上绑定到combo96?

On Error GoTo err_hand

Dim SearchStr As String
Dim oRec As ADODB.Recordset

Combo96.RowSource = ""
txtSearch.SetFocus
SearchStr = Trim(txtSearch.text)


Set oRec = New ADODB.Recordset ' [Client Number],

strQuery = "SELECT  replace(replace([Company],"","","""" ),"":"","""") as [Companys]  FROM tblClient  where company <> '' ORDER BY [Company] "
oRec.Open strQuery, Load_ribbon.get_Connection, adOpenKeyset, adLockOptimistic

Me.Combo96.RowSourceType = "Table/Query"
Set Me.Combo96.Recordset = oRec
oRec.Close


err_endit:
Set oRec = noting
Exit Sub

err_hand:

Call sendReport.SendErrorDetail("CMP-0701-" & Erl, "Can't Read [Clients] Data SRC-" & SearchStr & "-" & Err.Description & "-" & Err.Number)

' Here comes some Cheese!!!!
On Error GoTo Skippy
' Bounding probably failed Try manual
If Not (oRec Is Nothing) Then
    If oRec.RecordCount > 0 Then
        If oRec.RecordCount > 1000 Then
            MsgBox ("Too amany records found please be more specific")
        Else
          Me.Combo96.RowSourceType = "Value List"
            oRec.MoveFirst
            Do While Not RS.EOF
                Me.Combo96.AddItem RS![Company]
                oRec.MoveNext
            Loop
        End If
    End If
End If
Resume err_endit

Skippy:
MsgBox ("Run-Time Error CMP-0702-" & Erl & " Can't Read [Clients] Data")
Call sendReport.SendErrorDetail("CMP-0702-" & Erl, "Can't Read [Clients] Data SRC-" & SearchStr & "-" & Err.Description & "-" & Err.Number)
Resume err_endit

2 个答案:

答案 0 :(得分:0)

考虑使用Combo96.RowSource中的SQL查询而不是Combo96.Recordset属性。如果tblClient在连接后在本地可用,则在VBA中将组合框的行源设置为

SELECT replace(replace([Company],"","","""" ),"":"","""") as [Companys] FROM tblClient where company <> '' ORDER BY [Company]

显然,有关如何打开ADODB Recordset以将其分配到组合框/列表框的警告。请参阅此论坛主题:Populate Combo box using recordset

答案 1 :(得分:0)

事实证明这是Access运行时的问题。由于安装了2007和2010,因此有必要选择在哪个Access下运行。