Dim mrc As ADODB.Recordset
Set mrc = New ADODB.Recordset
Set mrc = ExecuteSQL(txtsql)
问题?当这时ExecuteSQL中返回为nothing 时
下面这句话会出错,问如何判断mrc值是有效的呢?
If mrc.EOF = False Then
End If
Set mrc = Nothing
mrc.Fields.Count
不过前提是要 ExecuteSQL(txtsql) 不出错
if mrc is nothing then
exit sub
end if
If not mrc is nothing then
mrc 有效
End if
If not mrc.EOF and not mrc.Bof = False Then
.....
End If
楼主的程序不对阿
ExecuteSQL应该是DAO的方法,mrc又被定义为ADODB.Recordset
怎么回事
Set mrc = ExecuteSQL(txtsql)有两种情况:
1 txtsql是查询语句,返回记录集
2 txtsql是数据库操纵语句,不返回记录集。
我的建议,对于第2种语句不要赋值给 mrc:
Call ExecuteSQL(txtsql)
如果一定要这么做,先判断一下:
Set mrc = ExecuteSQL(txtsql)
If IsNull Then Exit Sub
If Not mrc.EOF Then
......
End If
Set mrc = Nothing