473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Export Query As Text File Question

I'm trying to automate the export of a query to a text file using
code. If I export the query manually I get the exact result that I
want i.e. If I select the query then choose File/Export from the menu
bar, choose "Text" as the save format, and then select "fixed width"
as the export format, I end up with a fixed width text file with no
column headers.

I've tried to automate the process using:

DoCmd.OutputTo acOutputQuery, "qry_Test", acFormatTXT, "Test.txt",
True

This gives me the following unwanted issues. The column headers are
exported, the fixed width columns are separated by a vertical line,
and the rows are separated by dashes. Also the resulting text file
appears on the screen. I just want it to save and not appear. What do
I need to do to automate the process and end up with a text file that
is formatted the same as when I use the manual method? i.e no headers,
no separaters and a silent save to the text file.
Jul 2 '08 #1
3 10909
On Jul 2, 8:44*am, Wayne <cqdigi...@volcanomail.comwrote:
I'm trying to automate the export of a query to a text file using
code. *If I export the query manually I get the exact result that I
want i.e. If I select the query then choose File/Export from the menu
bar, choose "Text" as the save format, and then select "fixed width"
as the export format, I end up with a fixed width text file with no
column headers.

I've tried to automate the process using:

DoCmd.OutputTo acOutputQuery, "qry_Test", acFormatTXT, "Test.txt",
True

This gives me the following unwanted issues. *The column headers are
exported, the fixed width columns are separated by a vertical line,
and the rows are separated by dashes. *Also the resulting text file
appears on the screen. *I just want it to save and not appear. What do
I need to do to automate the process and end up with a text file that
is formatted the same as when I use the manual method? i.e no headers,
no separaters and a silent save to the text file.
Hi,

You can use following function (modified function of Joe Fellon, MVP)
to export query in fixed width format without headers. Call the
function with: ExportData ("qry_temp"). In my sample I have used table
with 3 fields.

Function ExportData(strExportFile As String)
Dim rs As Recordset
Dim strData As String
Dim intFileNum As Integer

'get file handle and open for output
intFileNum = FreeFile()

'opens the disk file
Open strExportFile For Output As #intFileNum

'open the recordset
Set rs = CurrentDb.OpenRecordset("qry_Test", dbOpenSnapshot)
'the numbered comments show the fixed width positions
With rs
Do Until .EOF
'this will pad the end of the field with spaces
strData = ![text1] & Space(20 - Len(![text1])) '1-20
strData = strData & ![text2] & Space(20 - Len(![text2]))
'21-40
strData = strData & ![text3] & Space(20 - Len(![text3]))
'41-60

'write out to file
Print #intFileNum, strData
.MoveNext
Loop
End With

Close #intFileNum
rs.Close
Set rs = Nothing
End Function

Regards,
Branislav Mihaljev
Microsoft Access MVP
Jul 2 '08 #2
Wayne wrote:
I'm trying to automate the export of a query to a text file using
code. If I export the query manually I get the exact result that I
want i.e. If I select the query then choose File/Export from the menu
bar, choose "Text" as the save format, and then select "fixed width"
as the export format, I end up with a fixed width text file with no
column headers.

I've tried to automate the process using:

DoCmd.OutputTo acOutputQuery, "qry_Test", acFormatTXT, "Test.txt",
True

This gives me the following unwanted issues. The column headers are
exported, the fixed width columns are separated by a vertical line,
and the rows are separated by dashes. Also the resulting text file
appears on the screen. I just want it to save and not appear. What do
I need to do to automate the process and end up with a text file that
is formatted the same as when I use the manual method? i.e no headers,
no separaters and a silent save to the text file.
Instead of OutputTo you might want to consider TransferText. You can
specify whether or not it has column headers and the type of delimiters.

First, click on your query and select from the menu File/SaveAs and
select external file and select Txt as the type. You will then be able
to set the specification for the output. Be sure to click the Advanced
button and save the specification. Once you have your specification
designed you can use it in TransferText.

Lambada
http://www.youtube.com/watch?v=5AfTl5Vg73A
Jul 2 '08 #3
Thanks to both Branislav and Salad for your replies. For my
particular situation at the moment, I'm going to use Salad's solution
because for me it's simpler.

Jul 3 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True after...
1
by: Bridget Willey | last post by:
I am using ACT 6 and am trying to "split" the database between records for customers and junk records. The accounts designated as "customers" have that word in the ID field, and I am using that...
10
by: Neil | last post by:
Hi guyz, just trying out this google feature so if i post if in the wrong area i appologize. now to my question. BTW i'm new to access programming, i've done a little vb6.0 and vb.net but access...
3
by: excyauseme | last post by:
Hi guys! Do you know what is the best way to export a text file, this one is a log file that is already comma delimited thru a module run by my access database, to an excel spreadsheet? I need to...
7
by: mattc66 via AccessMonster.com | last post by:
I need to create an EDI 850 Record Set. The EDI 850 Record set I am creating consists of 2-5 seperate tables all linked by the CustomerID and CustomerPO. Tables - tblOrder - >Link CustomerID...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
9
by: NEWSGROUPS | last post by:
I have data in a table in an Access 2000 database that needs to be exported to a formatted text file. For instance, the first field is an account number that is formatted in the table as text and...
17
by: chadh | last post by:
Hello, I'm having some troubles exporting a query to a csv file. I am able to use the doCMD.TransferText to output the query to the csv file, however, I cannot get it to use the Export...
8
by: iheartvba | last post by:
Hi I am using Access 2007 and am trying to export a query to a fixed length text file. I tried using the following code to export the text file: DoCmd.TransferText acExportFixed, , "qryFFRDeFile",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.