Re: TransferText Export Problem
- From: dogman_2000@xxxxxxxxxxx
- Date: Wed, 05 Sep 2007 01:41:26 -0700
On 4 Sep, 23:22, Rich P <rpng...@xxxxxxx> wrote:
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
.
- References:
- TransferText Export Problem
- From: dogman_2000
- Re: TransferText Export Problem
- From: Rich P
- TransferText Export Problem
- Prev by Date: Working with CSV Files
- Next by Date: Storing .wav files in MS Access DB
- Previous by thread: Re: TransferText Export Problem
- Next by thread: Form command
- Index(es):
Relevant Pages
|