473,569 Members | 2,839 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 15320
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.tx t 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 \
DateFourDigitYe ar -1
DateLeadingZero s 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
4348
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. Response.ContentType = "text/plain" Response.AddHeader("Content-Disposition", "attachment;filename=invoice.txt")
0
1667
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 columns get read as nulls). An example of an offending line is: J" Invalid " .... This is a text field that is between the two 'pipes' so I need it...
1
5953
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 pipe delimited text file. Appreciate any help!!!
1
3087
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
8521
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 "TransferText" Action in Macro. It gives me Export Type like "Export Delimited" But in that out put i am getting " (Double Quotes) & , (Commas). I want Filtered...
4
2422
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 apparently doesn't allow you to store export specs (makes sense since it has no local storage) so i'm not sure the TransferText method is going to do the...
1
3026
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 not sure why it's doing this. Any ideas how I can stop it from wrapping the text in the text file? -- Message posted via AccessMonster.com...
3
18895
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. Thanks for the help.
0
2220
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
9083
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 (MyText.txt). I have the following code in place, but it wont import properly. Its gives me type conversion errors as well as retains "|" in some fields...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2111
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 we have to send another system
1
1209
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.