Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2003, 07:26 AM
Authorized User
 
Join Date: Jun 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rylemer Send a message via MSN to rylemer Send a message via Yahoo to rylemer
Default Write Text file from recordset


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
 
Old December 5th, 2003, 08:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just swap your code around a bit so you open and close a text file inside of the Do ... Loop, something like this:
Code:
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
 
Old December 5th, 2003, 10:23 AM
Authorized User
 
Join Date: Jun 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rylemer Send a message via MSN to rylemer Send a message via Yahoo to rylemer
Default

Thanks Phil its working.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write to text file ? method Beginning VB 6 1 April 13th, 2006 01:54 AM
Write in A DOC File With Same Text Formatting Arshi VB How-To 0 February 5th, 2006 05:08 AM
Write ASCII text file muklee C# 1 December 12th, 2004 09:40 PM
Write column heading to text file cat_trio Access VBA 0 November 13th, 2003 02:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.