1. 程式人生 > >access vba 用recordset讀取表中資料的簡單方法

access vba 用recordset讀取表中資料的簡單方法

'strQuery是表名,查詢名等
Public  Function Getrs(Byval strQuery as string)  as ADODB.Recordset
Dim objRs As New ADODB.Recordset
on Error GoTo  Error_Getrs
objRs.open  strQuery,CurrentProject.connection
'程式除錯用
'Do While Not objRs.EOF
'        Debug.Print objRs(0) & vbTab & objRs(1) & vbTab & _
'                    objRs(2)
'        objRs.MoveNext
'Loop
Set  Getrs =objRs
Exit _Getrs:
Exit  Function
Error_Getrs:
MsgBox (Err.Description)
Resume Exit _Getrs
End  Function