Home > How-To Library > Database
Procedure which uses DAO to print all values in a recorset.
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** Sub PrintRec(strPath, Source) 'strPath is the path to the database 'Source is the source of the recordset. It could be a table or SQL query. Dim dbs As Database, tdf As TableDef Dim rst As Recordset, fld As Field Set dbs = OpenDatabase(strPath) Set rst = dbs.OpenRecordset(Source) With rst Do While Not .EOF 'Iterate through fields collection For Each fld In rst.Fields 'Print results to debug window Debug.Print fld.Name, fld.Value Next fld 'next record .MoveNext Loop Debug.Print End With 'close objects rst.Close Set rst = Nothing dbs.Close Set dbs = Nothing End Sub
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.