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) '对记录集的相关操作…… ……