473,503 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export Query to PIPE delimited text file

22 New Member
I'm using Access 2007-2010.
I want to export Query to PIPE delimited text file.
I don't know how to write code.

External Data tab Exports to Excel or txt file just fine. But I'm not seeing a way, (such as an Advanced checkbox), to specify the delimiter.

Is there a way to export the Query results and specify the delimiter?
Apr 15 '16 #1
3 15270
ADezii
8,834 Recognized Expert Expert
You can use VBA Code to Export a Query to a PIPE Delimited Text File. The following Code should do that that along with Field Names in the First Row. It is generic in nature and should accept any Query Name as an Argument to OpenRecordset(). I am in work where I do not have Microsoft Access installed, so this Code is purely off the top of my head. It may/may not be 100% accurate so accept it for what it is, basically AIR CODE.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim intFldCtr As Integer
  4.  
  5. Set MyDB = CurrentDB
  6. Set rst = MyDB.OpenRecordset("<Query Name here>", dbOpenSnapshot)
  7.  
  8. Open "C:\Test\Pipe.txt" For Output As #1
  9.  
  10. rst.MoveFirst
  11.  
  12. With rst
  13.   'Write Field names to Output File, delimiting by '|'
  14.   For intFldCtr = 0 To .Fields.Count - 1
  15.     strBuild = strBuild & .Fields(intFldCtr).Name & " | "
  16.   Next
  17.     Print #1, Left$(strBuild, Len(strBuild) - 3)    'Field Names, remove ending ' | '
  18.       strBuild = ""     'Must RESET
  19.  
  20.   Do While Not .EOF     'Values in Fields delimited by '|'
  21.     For intFldCtr = 0 To .Fields.Count - 1
  22.       strBuild = strBuild & .Fields(intFldCtr).Value & " | "
  23.     Next
  24.       Print #1, Left$(strBuild, Len(strBuild) - 3)      'Each Record, remove ending ' | '
  25.         strBuild = ""     'Must RESET for Next Record
  26.           .MoveNext
  27.   Loop
  28. End With
  29.  
  30. rst.Close
  31. Set rst = Nothing
What C:\Test\Pipe.txt will look like:
Expand|Select|Wrap|Line Numbers
  1. First | Last | MI | ZIP Code
  2. A | Putnick | O | 66543
  3. B | Birdseed |  | 98765
  4. C | Charlie | Y | 12340
  5. D | David |  | 
  6. E | Eddie | I | 19987
Apr 15 '16 #2
PhilOfWalton
1,430 Recognized Expert Top Contributor
Adezii's method looks good. Theres nothing worth watching on TV, so
here's a totally different approach, but I suggest you try it on a spare Accdb.
Create a query Query1
Expand|Select|Wrap|Line Numbers
  1. SELECT MSysIMEXSpecs.*
  2. FROM MSysIMEXSpecs;
  3.  
Run it. It will either give you an output if you have any saved Import/Export specifications, or give an error message that table MSysIMEXSpecs is not found.

In this case, select your query; On the Eternal Data Ribbon, select Export to Text File and run through everything. The critical thing is that after the export is done, a form comes up giving you the option of "Save Export Steps". Say yes.

This should create the MSysIMEXSpecs table

If you run Query1 again you should get a new record.

Here are the values you can try

DateDelim \
DateFourDigitYear -1
DateLeadingZeros 0
DateOrder
DecimalPoint .
FieldSeparator |
FileType 0
SpecID (This is an autonumber)
SpecName Test1
SpecType 1
StartRow
TextDelim ""
TimeDelim :

Save the record

Run this code
Expand|Select|Wrap|Line Numbers
  1. Sub ExportAsPipeDelimited()
  2.  
  3.     DoCmd.TransferText acExportDelim, "Test1", "YourQueryName", CurrentProject.Path & "\YourOutputFile.CSV"
  4.  
  5. End Sub
  6.  
No guarantees

Phil
Apr 15 '16 #3
informerFR
14 New Member
Thanks a lot for your great tricky solution Phil. You made my day !
Jan 15 '20 #4

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

Similar topics

2
4343
by: David Lozzi | last post by:
Howdy, I need to export some data to tab delimited text file. I was hoping to simply convert my datagrid to it, but I can't seem to figure out how. Here's what I got in the page header. ...
0
1663
by: Masa Ito | last post by:
I have pipe delimited (and comma/tab) files that I read with JET using a schema file. Occasionally a field has multiple quotes (") inside a single field - which chokes the line (the rest of the...
1
5951
by: Stella | last post by:
Help!!! Am extremely new to VBA. Want to set up code behind a button that will prompt the user for a table name(source of data) and file name(end result of export) and then export the data into a...
1
3078
by: Quentin | last post by:
I want to take a comma delimited text file and export it to excel format, using the comma as the delimiter. Any help on this would be great, thank you.
1
8510
by: bhapate1 | last post by:
Hi all, I Have a Table with 10 Columns, Among those i have Data in just 3 Columns. Rest of columns wil be blank. I want to Export that Table as a Pipe Delimited Text File. I am using...
4
2417
by: Ted Theo | last post by:
hello cdma enthusiasts. long time no speak. i have an .adp which is connected to a sql 2k back end from which i need to export a table to a tab delimited text file. the export text wizard...
1
3020
by: Leviathan via AccessMonster.com | last post by:
I'm trying to export an Access table to a pipe-delimited text file (with no text qualifier) and it keeps wrapping the text for one of the tables. None of the fields are particularly long, so I'm...
3
18882
by: AccessHunter | last post by:
Hi, I need to automate a process that would export a query to a text file, tab delimited. I know how to do it manually. Is there a way to automate the same? Please treat this as urgent. ...
0
2213
by: rhonda6373 | last post by:
Is it possible to change the format of an Excel file to a pipe delimited text file? How can I do that? Thanks in advance!
1
9057
by: vvasude2 | last post by:
Hello All, I am a new to VBA and Access. I would like to build code to be able to import a text file to a access database table. The text file is piped delimited. I have attached a sample of it...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7273
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
7322
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...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
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...
1
5000
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...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.