Access VBA Print Records to Text File

cms370

Registered User.
Local time
Today, 07:00
Joined
Jun 9, 2010
Messages
32
I am currently using the following statement from within Access VBA to print records to a file:

Print #FF, DLookup("[Column1]", "Some Table")

This part has worked. For the next step I would like to print the next records in the table, starting with the first record and ending with the last. How is this done? How do I tell Access through VBA that I want the next record? Once I understand this, I could then wrap a loop around it and extract the remaining records.

NOTE: I can not use the ".DoCmd.TransferText" because I need to add a header and trailer to this file.

Any simple example would be helpful.

Thanks.
 
Create a query, base a recordset on the query and loop through the recordset.

Look up DAO Recordset
 
Ok. Thanks for the information. I went through the link attached and tried out the following code:

Set db = CurrentDb

Dim rs As DAO.Recordset

Set rs = db.OpenRecordset("Some_Table", dbOpenTable)

Do While Not rs.EOF
Print #FF, DLookup("[Column1]", "Some_Table")
rs.MoveNext
Loop

After executing the code, it produces the same output for each line. In this particular example, each row that was printed to the text file was the same value. Any ideas on what I am missing here?

It does provide the correct number of output lines (60 in this case). Which matches the number of records in the table.
 
No 5 indicates where a field called MyField is retrieved from the recordset, hence, this:
Code:
Print #FF, rs![Column1]
 

Users who are viewing this thread

Back
Top Bottom