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

TransferText Export Problem

Hi All

I am using the docmd.transfertext to export my query as a .csv file.
I am using an export spec which is seperated by a pipe.

The problem I have is that I added an extra column onto the end of my
query and updated the spec.
The new column is an integer but when I export it, it always exports
as a text field i.e "100". With quotes around it.

I have tried manipulating the queries using either cDbl or NZ
functions but no luck.

I can't see anywhere in an export spec where I can change the setting
to ensure it gets exported as a number but if anyone has any ideas
please let me know.

Thanks
Andrew

Sep 4 '07 #1
2 3480
Hi Andrew,

Here is the easiest, most reliable way to export data to a csv file (or
text file) from Access -- use VBA.

Sub ExportDataToCSV()
Dim DB As DAO.Database, RS As DAO.Recordset, fld As DAO.Field, str1 As
String
Set DB = CurrentDb
Set RS = DB.OpenRecordset("tbl1")
Open "c:\1A\ExportTest1.csv" For Output As #1
Do While Not RS.EOF
str1 = ""
For Each fld In RS.Fields
str1 = str1 & fld & ","
Next
str1 = Mid(str1, 1, Len(str1) - 1) '--remove last ","
Print #1, str1
RS.MoveNext
Loop
Close #1
RS.Close
End Sub
Note: the Print command in the loop (Print #1, str1) prints/writes the
data to the csv file without quotations. There is also a Write command
(Write #1, str1) which would include double quotations around the
string. In my example I am not using quotes (using Print) so I combine
all the table fields into one string. If I wanted to surround each
table field with double quotes I would use the Write Command and do each
table field individually instead of combining the fields all into one
string. This is way more reliable than using Specs and much easier to
manipulate, maintain,...

You can find more information in the Access Help Files. Just copy this
code into a standard code module. If you have any questions on anything
-- just place the mouse cursor over the object in question (say the Open
command in Open "c:\1A\ExportTest1.csv"...) and press the F1 key. That
will bring up Access help on that topic.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 4 '07 #2
On 4 Sep, 23:22, Rich P <rpng...@aol.comwrote:
Hi Andrew,

Here is the easiest, most reliable way to export data to a csv file (or
text file) from Access -- use VBA.

Sub ExportDataToCSV()
Dim DB As DAO.Database, RS As DAO.Recordset, fld As DAO.Field, str1 As
String
Set DB = CurrentDb
Set RS = DB.OpenRecordset("tbl1")
Open "c:\1A\ExportTest1.csv" For Output As #1
Do While Not RS.EOF
str1 = ""
For Each fld In RS.Fields
str1 = str1 & fld & ","
Next
str1 = Mid(str1, 1, Len(str1) - 1) '--remove last ","
Print #1, str1
RS.MoveNext
Loop
Close #1
RS.Close
End Sub

Note: the Print command in the loop (Print #1, str1) prints/writes the
data to the csv file without quotations. There is also a Write command
(Write #1, str1) which would include double quotations around the
string. In my example I am not using quotes (using Print) so I combine
all the table fields into one string. If I wanted to surround each
table field with double quotes I would use the Write Command and do each
table field individually instead of combining the fields all into one
string. This is way more reliable than using Specs and much easier to
manipulate, maintain,...

You can find more information in the Access Help Files. Just copy this
code into a standard code module. If you have any questions on anything
-- just place the mouse cursor over the object in question (say the Open
command in Open "c:\1A\ExportTest1.csv"...) and press the F1 key. That
will bring up Access help on that topic.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
Thanks for the tip. Will give it a go!

I still don't understand why the field is exporting as text, but if
need be, when the file gets re-imported into access I can use a query
to change it to an integer.

Cheers

Sep 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sue | last post by:
Using WindowsXP and AccessXP in 2000 Mode When I run the following code, I get error 3027 "Cannot Update. Database or object is read only." StrFolder = "C:\Comic Box\WebStore Interface...
2
by: BigData | last post by:
I am attempting to create a delimited text file by using DoCmd.Transfertext as shown here. DoCmd.TransferText acExportDelim, "ExportSpec", "QryFinalExport", "Fileout.txt" This works fine as...
1
by: Trevor Best | last post by:
Just been having this problem when Exporting a query. DoCmd.TransferText acExportDelim, "GenMESR Export Specification", "qryGenMESRExport", Environ$("TEMP") & "\MESR.CSV", False I get the...
3
by: Oliver Gabriel | last post by:
Hi, i want to export a table for later import, using vba. That´s my code: export: filename = "C:\HVOtabelle.txt"
6
by: Tim Marshall | last post by:
IN trying to export a Jet query (an actual saved Jet querydef which is written against a pass through query - not that that should be a problem) to text via either the File->Export... menu item or...
0
by: Sean Howard | last post by:
I have a strange problem linking tab delimited text files in Access 2000 (I am running Windows XP), please try this and let me know if I am going mad. Step 1. Create the tab-delimited text...
5
by: Dave | last post by:
Hello, I have a possible problem exporting a text field that happens to contain dates (but is not a date field) when using TransferText in MS Access 2000. I am exporting a query to a text...
0
by: stuart | last post by:
I seem to have a problem with the use of the TransferText function. In 2 applications that I have, every few months, it seems to not export a few records from a table. In another application,...
7
ollyb303
by: ollyb303 | last post by:
Hi, I am having a bit of a problem with TransferText macro. I am using TransferText, Export Delimited (no field names) to export the results of a query as a .csv file. The query is based on...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...

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.