Export Query to CSV

  • Thread starter Jonathan Scott via AccessMonster.com
  • Start date
J

Jonathan Scott via AccessMonster.com

I am trying to export a query as a CSV file in Access97. TransferText seems
to want a table. I want to give it the string of a query. Am I forced to
create a Query class just to get this done?

Jonathan Scott
 
D

David Lloyd

Jonathan:

According to Access Help you can use a Query name for the TableName
parameter of the TransferText method:

TableName Optional Variant. A string expression that's the name of the
Microsoft Access table you want to import text data to, export text data
from, or link text data to, or the Microsoft Access query whose results you
want to export to a text file.


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


"Jonathan Scott via AccessMonster.com" <[email protected]>
wrote in message I am trying to export a query as a CSV file in Access97. TransferText seems
to want a table. I want to give it the string of a query. Am I forced to
create a Query class just to get this done?

Jonathan Scott
 
N

Nikos Yannacopoulos

Jonathan,

Access help can be misleading quite often, and this is one example. Even
though it says table, it will work just as fine wit a saved query; just
use the query name in the Tblae argument, and you'll be fine.

HTH,
Nikos
 
J

Jonathan Scott via AccessMonster.com

That's the thing, I don't want to create a Query class. I have a string for
a query in my code, which I want to have the result exported as a CSV.

My suggestion is to stop using Query classes. They hide dependencies, and
can keep you from effectively refactoring your code. Haven't you often
erased a query only to find that some other query is referencing it, but
you couldn't find it with the ctrl-f search function?

Still looking for a way,
Jonathan Scott
 
N

Nikos Yannacopoulos

Well, you can always do it the hard way if you want! That is, create the
SQL for the query at runtime, open that as a recordset, loop through the
records and write to a text file line by line. I use this technique for
exporting with non-standard delimiters etc.

Alternatively, you could create the querydef at runtime, export the
normal way and delete it, so you avoid the fuss of the recordset and
line-by-line export, while there's no danger of accidental deletion...
or you can just leave it there, and reconstruct it only if deleted or
altered. Personally I'm not very keen on creating and deleting objects
at runtime, in the interest of minimising bloat (which might not be much
of a concern if you compact on close).

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top