Connecting Tech Pros Worldwide Help | Site Map

Export Query as Fixed Length Text File

  #1  
Old April 17th, 2009, 01:19 AM
Familiar Sight
 
Join Date: Apr 2007
Posts: 162
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!
  #2  
Old April 17th, 2009, 01:48 PM
Lives Here
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,121
Provided Answers: 18

re: Export Query as Fixed Length Text File


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
  #3  
Old April 17th, 2009, 04:26 PM
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,450
Provided Answers: 56

re: Export Query as Fixed Length Text File


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.
  #4  
Old April 19th, 2009, 02:03 AM
Familiar Sight
 
Join Date: Apr 2007
Posts: 162

re: Export Query as Fixed Length Text File


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
  #5  
Old April 20th, 2009, 11:03 AM
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,450
Provided Answers: 56

re: Export Query as Fixed Length Text File


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.
  #6  
Old April 21st, 2009, 02:29 AM
Familiar Sight
 
Join Date: Apr 2007
Posts: 162

re: Export Query as Fixed Length Text File


Ok, I may not be following the steps probably, I will try again, following your steps.
  #7  
Old April 21st, 2009, 12:46 PM
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,450
Provided Answers: 56

re: Export Query as Fixed Length Text File


Let me know if that doesn't work for you. I remember being quite confused when I first noticed that happen.
  #8  
Old May 4th, 2009, 03:05 AM
Familiar Sight
 
Join Date: Apr 2007
Posts: 162

re: Export Query as Fixed Length Text File


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
  #9  
Old May 5th, 2009, 01:38 PM
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,450
Provided Answers: 56

re: Export Query as Fixed Length Text File


Very pleased to hear it :)

That means I'm still sane.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
DISTINCT UNION ALL query help (employees and dependents) zachster17 answers 5 June 10th, 2008 03:54 AM
DB2 Unload (to record sequential file) on NT possible? Timofmars answers 11 February 7th, 2007 10:05 AM
Altering a DBF File JimmyKoolPantz answers 9 November 5th, 2006 06:15 PM
Changing query to access different tables Marizel answers 10 November 13th, 2005 02:37 AM