会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 技巧 > Access技巧 > 模块函数VBA > 正文

根据不同的SQL语句获取记录集

时间:2009-05-19 09:07 来源:accessbbs 作者:Grant 阅读:
根据不同的SQL语句获取记录集

Public Function GetRS(ByVal strQuery As String) As ADODB.Recordset
    Dim RS As New ADODB.Recordset
    Dim conn As New ADODB.Connection
On Error GoTo GetRS_Error
    Set conn = CurrentProject.Connection
    RS.Open Trim$(strQuery), conn, adOpenKeyset, adLockOptimistic
    Set GetRS = RS

GetRS_Exit:
    RS.Close
    Set RS = Nothing
    conn.Close
    Set conn = Nothing
    Exit Function
GetRS_Error:
    MsgBox (Err.Description)
    Resume GetRS_Exit
End Function


'用法示例:
Dim RS As New ADODB.Recordset
Dim str As String
str = "select * from 员工表"
Set RS = GetRS(str)
'对记录集的相关操作……
……

RS.Close
Set RS=Nothing

(责任编辑:admin)

顶一下
(0)
0%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: