Query to text using code

  • Thread starter Thread starter Sujith
  • Start date Start date
S

Sujith

I have a query(MyQuery) which gets the following, need help in writing
code to convert them to the below structure and saving as text file. Is
this possible? Any help would be highly appreciated.
Thanks,
Sujith

Query:

Name A B C
ASD 20 11 1-Jan-05
BSD 20 5 2-Jan-05
CSD 0 0 3-Jan-05
EFD 20 3 4-Jan-05
GFD 10 22 5-Jan-05


Required Structure on text file:

<data>
<variable name = "MyQuery" >
<row>
<column>Name</column>
<column>A</column>
<column>B</column>
<column>C</column>
</row>
<row>
<column>ASD</column>
<column>20 </column>
<column>11 </column>
<column>01 Jan 05</column>
</row>
<row>
<column>BSD</column>
<column>20 </column>
<column>5 </column>
<column>02 Jan 05</column>
</row>
<row>
<column>CSD</column>
<column>0 </column>
<column>0 </column>
<column>03 Jan 05</column>
</row>
<row>
<column>EFD</column>
<column>20 </column>
<column>3 </column>
<column>04 Jan 05</column>
</row>
<row>
<column>GFD</column>
<column>10 </column>
<column>22 </column>
<column>05 Jan 05</column>
</row>
</variable>
</data>
 
Create a report from your saved query, then output it to a text file from a
button or whatever:

DoCmd.OutputTo acOutputReport, "MyQueryReport", "MS-DOSText(*.txt)",
"C:\Temp\MyQuery.txt"
 
SusanV said:
Create a report from your saved query, then output it to a text file from a
button or whatever:

DoCmd.OutputTo acOutputReport, "MyQueryReport", "MS-DOSText(*.txt)",
"C:\Temp\MyQuery.txt"

I dont get the format that is required by this method
sujith
 
I dont get the format that is required by this method

Then you didn't set up the Report to produce the format that was
required. Susan was suggesting that you craft the Report specifically
to produce that format - a nontrivial task. Did you just use the
Report Wizard? If so, that wasn't what she was suggesting!

John W. Vinson[MVP]
 
Exactly! Thank you John for clarifying.

SusanV

John Vinson said:
Then you didn't set up the Report to produce the format that was
required. Susan was suggesting that you craft the Report specifically
to produce that format - a nontrivial task. Did you just use the
Report Wizard? If so, that wasn't what she was suggesting!

John W. Vinson[MVP]
 
SusanV said:
Exactly! Thank you John for clarifying.

SusanV
The reason i did not want to use report was that i will have to create
different reports for every query, sorted the problem with a bit of
research on the net using "print" option in vba
Thanks for your quick response
Have a great new year
Sujith
 

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

Back
Top