没有用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
顺便请大侠帮看看我的通用模块的思路对不对, 有无要改进的地方.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
解决方案 »
- 如何更改TabStrip的背景色啊?
- 如何将一个已知文字添加到任何一个已获焦点的文本框的当前光标之后
- VB操作Excel文件的问题
- 求一个用ADO的pagesize属性分页显示mshflexgrid的例子(数据量较大,10000条以上).
- 重装了SQLserver后,恢复不料master数据库了,大家帮忙呀!
- 检查excel数据输入模式是否处于打开状态,还是会出错,如何解决!
- 如何将多个表的数据查询到一个记录集中?
- 关于IIS应用程序的两个问题
- 泰山兄,赶紧将719e-s的驱动发给我呀,听不起音乐,我快急疯了!!!
- 人体周期函数的问题(40分,先回答再给分!)
- 问个简单问题(送20分)
- 【问】如何用ListView在虚拟列表形式下实现Checked功能?
Dim i As Integer
For i = 0 To 5
if not objptr(adoRec(i))=0 then
Call adoRecClose(adoRec(i))
end if
Next i
End Sub