Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a text type output file

Status
Not open for further replies.

EdAROC

Programmer
Aug 27, 2002
93
US
New territory for me ... I need to create a text file of information about A/P checks we create. The file will be FTP'd to the bank.

Created a query to retrieve the checks produced for a specified date. Now I'm stuck. Didn't see an example in Tek-Tips, nor in the "Access 97 Developer's Handbook". Let me know if I missed anything.

Output file contains a header (HDR) line/record, a line for each check, and a trailer (EOF) line/record. Each line/record is 102 characters long. ("Record" is their terminology).

I'm guessing the solution is using VBA to open a file, create a first (HDR) line, create a line for each check (each row in the query and some - Void - entries would be excluded, create an EOF record, and close the file. Each line of the text file is a text string, so I will need to create a single text string from all the query columns. That said, I don't know how to do any of the above (including programming loop to look at each row of the query) except for creating the text string. :)

Is there another solution? If not can someone direct me to an example of the coding? Or can you do all this within a reply message.
 
Here's some skeleton code to get you started
Code:
Dim nH     As Integer
Dim Buffer As String
Dim rs     As DAO.Recordset

nH = Freefile
Open "SendToTheBank.txt" For Output Access As #nH

Buffer = [blue]Format the Header Here[/Blue]
Print #nH, Buffer

Set rs = CurrentDb.OpenRecordset("Select ... From ... etc.")

Do Until rs.EOF
   Buffer = [blue]Format the Output line Here[/blue]
   Print #nH, Buffer
   rs.MoveNext
Loop
Set rs = Nothing
Close nH
I've used DAO syntax here but ADO uses much the same constructs (except that it will be a Connection object rather than a Database object.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top