LZ大哥,自定义函数到书上哪里去找啊?
貌似我写的函数,在论坛里都贴过几会了,函数原形如下:
Public Function TransactSQL(ByVal sql As String) As ADODB.Recordset
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
'--------------------------------
'创建连接
Set con = New ADODB.Connection
'--------------------------------
'创建记录集
Set rs = New ADODB.Recordset
On Error GoTo TransactSQL_Error
strConnection = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\cims.mdb"
strArray = Split(sql)
'----------------------------
'打开连接
con.Open strConnection
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), con, adOpenKeyset, adLockOptimistic
'---------------------------
'返回记录集
Set TransactSQL = rs
iflag = 1
Else
'---------------------------
'执行SQL
con.Execute sql
'---------------------------
'数据库打开标志置为打开状态
iflag = 1
End If
TransactSQL_Exit:
Set rs = Nothing
Set con = Nothing
Exit Function
TransactSQL_Error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume TransactSQL_Exit
End Function
荷,LS的代码现在写的蛮标准的嘛.我建议再加点东西.
TransactSQL_Error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume TransactSQL_Exit
改成
TransactSQL_Error:
MsgBox "查询错误:" & Err.Description,Err,"窗体或模块名.TransactSQL"
iflag = 2
Resume TransactSQL_Exit
这样一来如果程序很大的话,只要出错,就很容易找到错误位置,那样找错误会很轻松.
LZ大哥,自定义函数到书上哪里去找啊?
貌似我写的函数,在论坛里都贴过几会了,函数原形如下:
Public Function TransactSQL(ByVal sql As String) As ADODB.Recordset
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
'--------------------------------
'创建连接
Set con = New ADODB.Connection
'--------------------------------
'创建记录集
Set rs = New ADODB.Recordset
On Error GoTo TransactSQL_Error
strConnection = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\cims.mdb"
strArray = Split(sql)
'----------------------------
'打开连接
con.Open strConnection
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(sql), con, adOpenKeyset, adLockOptimistic
'---------------------------
'返回记录集
Set TransactSQL = rs
iflag = 1
Else
'---------------------------
'执行SQL
con.Execute sql
'---------------------------
'数据库打开标志置为打开状态
iflag = 1
End If
TransactSQL_Exit:
Set rs = Nothing
Set con = Nothing
Exit Function
TransactSQL_Error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume TransactSQL_Exit
End Function
[此贴子已经被作者于2007-11-6 20:51:10编辑过]
荷,LS的代码现在写的蛮标准的嘛.我建议再加点东西.
TransactSQL_Error:
MsgBox "查询错误:" & Err.Description
iflag = 2
Resume TransactSQL_Exit
改成
TransactSQL_Error:
MsgBox "查询错误:" & Err.Description,Err,"窗体或模块名.TransactSQL"
iflag = 2
Resume TransactSQL_Exit
这样一来如果程序很大的话,只要出错,就很容易找到错误位置,那样找错误会很轻松.
好主意 支持!
[此贴子已经被作者于2007-11-6 20:49:43编辑过]