没有用New 申明Recordset(5)数组,Open/Close Recordset都做成了模块, 窗体结束时,数组有可能没有全部建立, call adoRecClose 遇到没有建立的Reccordset就发生错误, 问: 怎样测试Recordset 已建立,已建立的才执行关闭, 大侠请.
顺便请大侠帮看看我的通用模块的思路对不对, 有无要改进的地方.Dim adoRec(5) As ADODB.RecordsetPrivate Sub Form_Unload(Cancel As Integer)
    Dim i As Integer
    For i = 0 To 5
        Call adoRecClose(adoRec(i))
    Next i
End Sub模块:
Public Function adoRecOpen(adoRecCon As ADODB.Connection, adoRecOp As ADODB.Recordset, txtSQL As String, _
                           Optional lErrNo As Long, Optional sErrDescr As String) As Boolean
On Error GoTo adoRecOpenErr
    adoRecOpen = False
    Set adoRecOp = New ADODB.Recordset
    If adoRecOp.State <> adStateOpen Then
        With adoRecOp
            .Open txtSQL, adoRecCon, adOpenDynamic, adLockOptimistic, adCmdText
        End With
    End If
    adoRecOpen = True
    Exit Function
adoRecOpenErr:
    lErrNo = Err.Number
    sErrDescr = Err.Description
    MsgBox "SQL:" & txtSQL & vbCrLf & _
           "Description (" & Err.Number & ") : " & Err.Description, vbExclamation, "Open ADO.Recordset Error:"
    End
End FunctionPublic Function adoRecClose(adoRecCl As ADODB.Recordset, Optional lErrNo As Long, Optional sErrDescr As String) As Boolean
On Error GoTo adoRecCloseErr
    adoRecClose = False
    
    If adoRecCl.State <> adStateClosed Then
        adoRecCl.Close
        Set adoRecCl = Nothing
    End If
    adoRecClose = True
    Exit Function
adoRecCloseErr:
    lErrNo = Err.Number
    sErrDescr = Err.Description
    MsgBox "错误: " & Err.Description, vbExclamation, Err.Number
    End
End Function