473,383 Members | 1,980 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,383 software developers and data experts.

Export Query as Fixed Length Text File

171 100+
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:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText acExportFixed, , "qryFFRDeFile", "C:\qryFFRDeFile.txt", True
Access asks for a specification name, now here lies the challenge, how do I create an export specification I have tried the following 2 methods:

In access 2007:
Step1: I right clicked the query and chose export to text file
Step2: I entered the location I wanted it exported to as C:\qryFFRDeFile.txt
Step3: Saved the Export Specification and Pressed ok to export
Result: It exports... and thats it, I can access the saved specification in the saved imports section under the external data tab, but can't use it in the vba code listed above (I get an error saying the specification doesn't exist), even if I could call it in the code, it's not the specification I want because I haven't determined the fixed lengths.

In Access 2003:

So now I go and try the same thing in Access 2003, when I right click export on the query, it doesn't even bring up the export wizard, it just asks me for the location and exports it.

Now if that wasn't enough, there are 3 parts to the fixed length file all three of which have different lengths and number of columns. So the solution would be if I could export the first part, then export the second part to the same file, but instead of overwriting the file it would append the query to the first part that had previously been exported, and the third part would be exported in the same manner.

Please help (Not that I needed to say that)

Thanks Guys!
Apr 17 '09 #1
8 18718
ChipR
1,287 Expert 1GB
The second argument to DoCmd.TransferText would be the name of your specification. You should also see it listed under your Tables.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText acExportFixed, "myExportSpec", "qryFFRDeFile", "C:\qryFFRDeFile.txt", True
Apr 17 '09 #2
NeoPa
32,556 Expert Mod 16PB
To create an Import/Export Specification you should export the data via the manual process first. It may be easier to use a table properly pre-configured for this the first time.
  1. Select File / Export.
  2. Select Type of Text files.
  3. Enter (or select) a File name.
  4. For this one it helps to use the extension .txt.
  5. Click on Export button.
  6. Select Fixed Width.
  7. Click on Advanced... button.
  8. Select the options required on that screen first.
  9. Next, go down to the Field Information section and look at the columns.
    1. Select columns across from the left to the right. Ensure the mouse moves beyond the right border to catch any hidden columns there.
    2. Double-click on a column separator to show all hidden (width=0) columns.
    3. Repeat for any columns at the left.
  10. Now configure each field as required.
  11. Click on Save As....
  12. Enter your new specification name.
This specification is now available for use in your code.
Apr 17 '09 #3
iheartvba
171 100+
Hi ChipR AND NeoPa,
Firstly ChipR please read after my transfertext code, I can't actually create the Export Specification.

NeoPa, actually I do know how to create the export specification like you showed me in access 2003 (not in access 2007 though). The problem is that this only occurs if the export wizard runs I.E. the box that pops up and allows you to do steps 6-11. It used to come up automatically but now access just exports the report after step 5. It doesn't make sense. Also if someone knows how to save and then programatically call an export specification in Access 2007 please let me know.

Thank you
Apr 19 '09 #4
NeoPa
32,556 Expert Mod 16PB
Are you following all the instructions precisely? I have had a similar issue, but if I follow those steps it uses the wizard (including specifying the source as a table to start).

I have no info on, or experience with, Access 2007 though.
Apr 20 '09 #5
iheartvba
171 100+
Ok, I may not be following the steps probably, I will try again, following your steps.
Apr 21 '09 #6
NeoPa
32,556 Expert Mod 16PB
Let me know if that doesn't work for you. I remember being quite confused when I first noticed that happen.
Apr 21 '09 #7
iheartvba
171 100+
heheh, following the steps in Post # 3 worked, I am so sure I did the same thing before and it didn't work, it even works in Access 2007.

Thanks Mate
May 4 '09 #8
NeoPa
32,556 Expert Mod 16PB
Very pleased to hear it :)

That means I'm still sane.
May 5 '09 #9

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

Similar topics

2
by: ezelasky | last post by:
We are using the bcp utility (via APIs) to export data from a SQL table in a fixed format text file. BCP is inserting spaces for a field if the field contains a NULL. This is fine with us except...
2
by: Darin Browne | last post by:
I have to create a fixed length text file and was hoping someone could point me to an example or resources that could help explain how it is done in C#. Thanks.
0
by: suryar | last post by:
Hi please help me some one in my company i want to write a script in vb to write a text file but the source file is an excel file i want write a text or dat file with fixed lengths maping with ...
4
by: sanparab | last post by:
I am a new user for MS Access 2003, I want to transfer a data of Fixed lenght text file into Access Tabel. The data is contained of four Record Set those are as follows 1. The header record...
0
by: Mic | last post by:
Hi, I just started using Visual Web Developer Express 2005. I need to print a dataset that is populated from a fixed length text file. No problem with this part. So I am trying to use a...
18
by: loisk | last post by:
Hi, I have the following query to export queried results into a text file, comma delimited. Now I need to export it into a text file, but with fixed length, not with commas. Can anybody help me...
6
by: =?Utf-8?B?VGFydW4=?= | last post by:
Hi, I have to generate a fixed length text file.I have a file formats like fields details as well as its length and position.what actually i have to do that i will get the data from the databas...
6
by: ssharpjr | last post by:
Hi Guys, I'm new to Python (mostly) and I'm wanting to use it for a new project I'm faced with. I have a machine (PLC) that is dumping its test results into a fixed- length text file. I need...
2
by: Edwin.Madari | last post by:
#your thought is right. ======================================================= def sizes2fields(sizes): d = begin = 0 for i in sizes: if begin: end = begin + i else: end = i...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.