CodeItBetter Programming Another VB Programming Blog

Procedure which uses DAO to print all values in a recorset.

Posted on July 3, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'Database - Procedure which uses DAO to print all values in a recorset.
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
Filed under: Database Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.