Subject: Write Text file from recordset
Posted By: rylemer Post Date: 12/5/2003 6:26:25 AM

ID Name
1  Rylemer
2  Charles
3  Bill

In the ex. above is the records in my table. I have 3 records in the table then I want to put every records in a text file.

ex. Rylemer I want to write in a text file I will call it elmer.txt
then next Charles I want to write also in a text file and want to call it Charles.txt same as record no. 3


 Here is my code

Dim rs As DAO.Recordset
Dim sPath As String
    sPath = "C:\temp\Temptext.txt"
    Set rs = CurrentDb.OpenRecordset("FEDINCOUNT")
        Open sPath For Output As #1
            Do Until rs.EOF
                FEDEIN = rs("FedEIN")
                Print #1, FEDEIN
                
                rs.MoveNext
            Loop
        Close #1
            rs.Close
    Set rs = Nothing

How you can help me

Thanks
Rylemer
Reply By: pgtips Reply Date: 12/5/2003 7:19:18 AM
Just swap your code around a bit so you open and close a text file inside of the Do ... Loop, something like this:

Dim rs As DAO.Recordset
Dim sPath As String
sPath = "C:\temp\" ' just have the directory here
Set rs = CurrentDb.OpenRecordset("FEDINCOUNT")
Do Until rs.EOF
    Open sPath & rs("FedEIN") & ".txt" For Output As #1
    FEDEIN = rs("FedEIN")
    Print #1, FEDEIN
    Close #1
    rs.MoveNext
Loop
Close #1
rs.Close
Set rs = Nothing


BTW it's much safer to use FreeFile rather than #1 for your file numbers.

rgds
Phil
Reply By: rylemer Reply Date: 12/5/2003 9:23:23 AM
Thanks Phil its working.

Go to topic 7256

Return to index page 992
Return to index page 991
Return to index page 990
Return to index page 989
Return to index page 988
Return to index page 987
Return to index page 986
Return to index page 985
Return to index page 984
Return to index page 983