以下代码运行到If Not l_adorsClose.EOF Then就会报对象变量或 With 块变量未设置的错  百度以后将   Dim l_adorsClose As ADODB.Recordset 改为  Dim l_adorsClose As New ADODB.Recordset后又报3701,对象关闭时,不允许操作
求各位大佬帮忙Dim l_sqlClose As String
    Dim l_adorsClose As ADODB.Recordset
    l_sqlClose = "select cld01 close_date,cld02 close_time,cld05 open_date from cld_file where cld03='Y'"      'B2B关帐时间表
    Set l_adorsClose = exesql("B2B", l_sqlClose)
    If Not l_adorsClose.EOF Then
        l_CloseDate = l_adorsClose("close_date")
        l_CloseTime = l_adorsClose("close_time")
        l_OpenDate = l_adorsClose("open_date")
    End If
    l_CurrentDate = Format(Now(), "YYYYMMDD")
    l_CurrentTime = Format(Now(), "HHMMSS")
    '如果当前日期在关帐日期后,开帐日期前,就退出程式(关帐期间不运行)
    If (l_CurrentDate = l_CloseDate And l_CurrentTime >= l_CloseTime) Or (l_CurrentDate > l_CloseDate And l_CurrentDate < l_OpenDate) Then
        Exit Sub
    End If

解决方案 »

  1.   

     exesql("B2B", l_sqlClose) 返回值是个ADODB.Recordset对象?可以把 exesql("B2B", l_sqlClose) 的代码贴上来看一下
      

  2.   

    以下是对数据库进行操作
    Public Function exesql(SYSID As String, ByVal sSQL As String) As ADODB.Recordset      '传递参数系统别,便于数据库连接:
          'MES表示MES数据库连接字串;
          'SAP表示SAP数据库连接字串;
          'B2B表示B2B数据库连接字串;
          '自身并以Reconderset对象的形式返回,便于数据库操作。
          Dim cnn1 As New ADODB.Connection
          Dim adors1 As New ADODB.Recordset
          Dim arry() As String      '异常处理
          On Error GoTo exesql_err
          '用Split 函数产生各个字串的数组
          arry = Split(Trim$(sSQL))
          '打开数据库连接 By 不同的系统类别
          Select Case UCase$(Trim$(SYSID))
                 Case "B2B"
                      cnn1.Open g_b2b
                 Case "SAP"
                      cnn1.Open g_sap
                 Case "MES"
                      cnn1.Open g_mes
                Case "B2BDS1"
                      cnn1.Open g_b2bds1
          End Select
          '判断SQL执行语句到底属于那种操作
          If InStr("INSERT,DELETE,UPDATE", UCase$(arry(0))) Then
             cnn1.Execute sSQL
          Else
            With adors1
                .CursorLocation = adUseClientBatch
                .CursorType = adOpenKeyset
                .LockType = adLockOptimistic
                .Open sSQL, cnn1
           ' Set .ActiveConnection = Nothing
            End With
            Set exesql = adors1
          End If
    exesql_exit:
          Set adors1 = Nothing
          'cnn1.Close
          Set cnn1 = Nothing
          Exit Function
    exesql_err:
          Resume exesql_exit
    '      MsgBox  Err.Description
    End Function
      

  3.   

    Set adors1 = Nothing你这句已经把对象设为nothing了,哪能返回你想要的recordset啊
      

  4.   

    exesql_exit:
          Set adors1 = Nothing
          'cnn1.Close
          Set cnn1 = Nothing改成
    exesql_exit:
          'Set adors1 = Nothing
          'cnn1.Close
          'Set cnn1 = Nothing试试
      

  5.   

    请问你们用的是v6或vb.net ?