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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export MS Access query results to .txt file 1

Status
Not open for further replies.

muntz70

Programmer
Dec 5, 2003
25
0
0
US
Howdy all!

I have been trying to export the results of a ms access query to a .txt file. Everything I have tried always formats the file as such:

"data1","data2","data3"

I would like it to be like this:

data1,data2,data3

Now, I could just write a simple routine to go through the text file and remove the quotes, but that seems a bit... sloppy. There has got to be a way to export the results of the query into a text file without any quotes.

Any suggestions?

 
Oh.. I'm wanting to do this from within a Delphi application. The query was created within the access database. I was calling the query with ADO component then looping though the results and writing it to a .txt file.

Sorry that I did not make that clear above.

 
I would do something like this:
Code:
Query1.first;
while not Query1.eof do
begin
  s := '';
  for i := 0 to Query1.FieldCount -1 do
  begin
    s := s + Query1.Fields[i].AsString;
    if i < Query1.FieldCount - 1 then
      s := s + ',';
  end;
  //output s to your text file.
end;
There are several ways to write data to a text file. In this case I would probably set up a TextFile using AssignFile and Rewrite and then use WriteLn to output the string to the file.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Oops! I forgot to add the call to "Query1.Next" in the while loop. You can put it either before or after the output code.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Worked like a charm! Funny thing is... I did it that way once before. I must have missed *something*.

Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top