Query to Pipe Deliminated TXT file

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
Access 2007:
I have a query that I am exporting to a pipe deliminated txt file. The problem I am having is that one field is a "short date", but the export converts/adds the time format.

The field holds "09/23/2016", but the export will show as "9/23/2016 00:00.0". I've tried changing the field to Text format, but still get the same result.....my export needs to be "mm/dd/yyyy", retaining any leading zeros.

Any ideas?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
In your query, use the FORMAT function on this field (in a Calculated field), which will convert it to Text, and it will be formatted exactly as you want, i.e.
FORMAT([myDateFieldName],"mm/dd/yyyy")
 
Last edited:
Upvote 0
In your query, use the FORMAT function on this field (in a Calculated field), which will convert it to Text, and it will be formatted exactly as you want, i.e.
FORMAT([myDateFieldName],"mm/dd/yyyy")

I tried that, too. No dice. :confused:
 
Upvote 0
I tried that, too. No dice.
Then I fear that you may have done something wrong. I have use this method quite a lot with success.
Note that I am talking about creating a Calculated field using the FORMAT function, not using the formatting property under each field.

Can you post the SQL code of your query, and the let us know the name of the field in question.
 
Last edited:
Upvote 0
After further research, I was able to resolve my issue by pushing my query/recordset to Excel and using a variation of the following.

Code:
Dim fso As Object
Dim TS As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set TS = fso.CreateTextFile("C:\test.txt")
 
    LR = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To LR
        strTemp = "|"
        For x = 1 To 24
            strTemp = strTemp & Cells(i, x) & "|"
        Next x
        strTemp = Temp & vbCrLf
        TS.Write Temp
    Next i
 TS.Close
 
Upvote 0

Forum statistics

Threads
1,221,798
Messages
6,162,027
Members
451,737
Latest member
MRASHLEY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top