俺有一个程序,原来采用Access 97, 运行得很好,将其升级到Access 2000后。
出现问题,出现问题的模块为以下模块'查询邮编及其它
Private Function QueryZip(ZipStr As String, ResultRecord As ADODB.Recordset) As Boolean
   Dim SQLStr As String
   Dim comZip As ADODB.Command
   Dim tempStr As String
          
   If Len(Trim(ZipStr)) = 0 Then
       QueryZip = False
   Else
        tempStr = "'%" & Trim(ZipStr) & "%'" '转成 *湘潭*这样的查询字符串
        SQLStr = "SELECT short,province,city,zone,post " _
                & " FROM Zip" _
                & " WHERE ( short LIKE " & tempStr & ") OR (" _
                & " province LIKE " & tempStr & ") OR (" _
                & " city LIKE " & tempStr & ") OR (" _
                & " zone LIKE " & tempStr & ") OR (" _
                & " post LIKE " & tempStr & ")"
                
        Set comZip = New ADODB.Command
        With comZip
          .ActiveConnection = glbSD.gQueryDB.cnnDB
          .CommandText = SQLStr
        End With
        
        Set rstZip = New ADODB.Recordset
        
        '
        '以下为出现问题的语句
        '提示 Open的 _RecordSet 方法出错。
        '
  
        rstZip.Open comZip, , adOpenKeyset, adLockOptimistic, adCmdText
        Set comZip = Nothing
        Set ResultRecord = rstZip
   
        QueryZip = True
   End If
   
End Function1、我已经将数据库转成Access 2000的版本
2、strProvider = "Provider=Microsoft.Jet.OLEDB.4.0;" 而且很奇怪的问题是,在一个数据库中有多张表,而只有一个表的查询出错。
请问大家有没有碰到过这种情况,是如何解决的?

解决方案 »

  1.   

    在DAO时代遇到过数据库无法打开等,是用的ado2.5以上的吗?有没有用set rst=cmd.execute呢?
      

  2.   

    我试了不是这个问题,而且表名为zip,非保留字,改成myzip也是出错。
    SQLStr = "SELECT short,province,city,zone,post " _
                    & " FROM Zip" _
                    & " WHERE ( short LIKE " & tempStr & ") OR (" _
                    & " province LIKE " & tempStr & ") OR (" _
                    & " city LIKE " & tempStr & ") OR (" _
                    & " zone LIKE " & tempStr & ") OR (" _
                    & " post LIKE " & tempStr & ")"
    大家看我这句有没有出错,问题是我在ACCESS97也没有一点问题!