这是更多示例代码。它说明了两种不同类型的记录集的用法。您可能希望阅读VBA陷阱:
Allen Browne的Recordsets和Access
2002和更高版本的Access中的保留字列表 。
Dim rs As DAO.RecordsetDim rs2 As ADODB.RecordsetSet rs = CurrentDb.OpenRecordset("querycrit")Set rs2 = CreateObject("ADODB.Recordset")rs2.ActiveConnection = CurrentProject.ConnectionFor Each tdf In CurrentDb.TableDefs'EDIT: TableDefs includes Microsoft System tables and ''these should never be tampered with. They all begin with Msys ''so we can leave them out of the loop here. ' If Left(tdf.Name, 4) <> "msys" And tdf.Name <> "querycrit" Then rs.MoveFirst strSQL = "SELECt * From [" & tdf.Name & "] WHERe " Do While Not rs.EOF On Error Resume Next Debug.Print tdf.Name rs2.Open strSQL & " " & rs![query] If Err.Number = 0 Then On Error GoTo 0 If Not rs2.EOF Then Debug.Print rs![Error] Debug.Print rs2.GetString End If End If Err.Clear rs2.Close rs.MoveNext Loop End IfNextEnd Sub


