By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

Appending data to .txt file from Query

P: 3
Does anyone know how to append data from a MS Access query to a .txt file. I have a process to import data and check for errors. I would like to report the errors to a text file after every import without deleting the previous results (ie the Transfer text method)
Thanks
Oct 27 '06 #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,344
You would have to write code to process through the data (ADO or DAO RecordSet) and write to a text file opened using the Open Statement.
The help system will give you more details on those facilities.
Oct 27 '06 #2

NeoPa
Expert Mod 15k+
P: 31,344
Of course, you could also write a new, and separate, file using TransferText, then use Shell to run a COPY command that appends the two files together into a resultant file. There are all sorts of possibilities there.
Jan 11 '09 #3

ADezii
Expert 5K+
P: 8,619
@ingrammx
Sometimes, I simply prefer a very Low Level approach such as the following code which will write the Values of 3 Fields in a Recordset to a Comma Delimited Text File. It this Format, it can then be easily Imported into a host of Database, and other varied, Applications.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim MyDB As DAO.Database
  3. Dim rstEmployees As DAO.Recordset
  4. Dim intFileNum As Integer
  5. intFileNum = FreeFile()
  6. Open "C:\Employee.txt" For Append As #intFileNum
  7. Set MyDB = CurrentDb()
  8. Set rstEmployees = MyDB.OpenRecordset("Employees", dbOpenForwardOnly)
  9. With rstEmployees
  10.   Do While Not .EOF
  11.     Write #intFileNum, ![FirstName], ![LastName], ![Address]
  12.       .MoveNext
  13.   Loop
  14. End With
  15. Close #intFileNum
  16. rstEmployees.Close
  17. Set rstEmployees = Nothing
  18.  
Sample data in Employee.txt
Expand|Select|Wrap|Line Numbers
  1. "Nancy","Davolio","507 - 20th Ave. E. Apt. 2A"
  2. "Andrew","Fuller","1313 Mockingbird Lane"
  3. "Janet","Leverling","722 Moss Bay Blvd."
  4. "Margaret","Peacock","4110 Old Redmond Rd."
  5. "Steven","Buchanan","14 Garrett Hill"
  6. "Michael","Suyama","Coventry House Miner Rd."
  7. "Robert","King","Edgeham Hollow Winchester Way"
  8. "Laura","Callahan","4726 - 11th Ave. N.E."
  9. "Anne","Dodsworth","7 Houndstooth Rd."
Jan 11 '09 #4

NeoPa
Expert Mod 15k+
P: 31,344
Sorry ADezii. I resurrected this thread by accident yesterday when looking at my first screen of subscribed threads :D

I don't think the OP is likely to see this. It doesn't hurt to have answers visible for searchers though.
Jan 11 '09 #5

ADezii
Expert 5K+
P: 8,619
@NeoPa
Gotcha, no problemo!
Jan 12 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.