By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,161 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,161 IT Pros & Developers. It's quick & easy.

Working with CSV Files

P: n/a
A2003.

I have a CSV file with a header row that I'd like to work with using VBA. I
know that you can link to a CSV file from the database window in a similar
way to linking to an XLS file, my question is can you link to a CSV file in
code and does anyone have any working examples I could take a look at?

Many thanks.

Keith.

Sep 5 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Keith Wilby wrote:
A2003.

I have a CSV file with a header row that I'd like to work with using
VBA. I know that you can link to a CSV file from the database window in
a similar way to linking to an XLS file, my question is can you link to
a CSV file in code and does anyone have any working examples I could
take a look at?

Many thanks.

Keith.
Would something like this work?
Sub LinkText()
DoCmd.TransferText acLinkDelim, , "Testing", "C:\Junk.Txt", True
MsgBox "Done"
End Sub
Sep 5 '07 #2

P: n/a
"Salad" <oi*@vinegar.comwrote in message
news:13*************@corp.supernews.com...
>
Would something like this work?
Sub LinkText()
DoCmd.TransferText acLinkDelim, , "Testing", "C:\Junk.Txt", True
MsgBox "Done"
End Sub
Hi salad, yes it does and is much simpler than I thought, although it links
all of the data to one field. Can this method handle CSVs?

Many thanks.

Keith.

Sep 5 '07 #3

P: n/a
Keith Wilby wrote:
"Salad" <oi*@vinegar.comwrote in message
news:13*************@corp.supernews.com...
>>
Would something like this work?
Sub LinkText()
DoCmd.TransferText acLinkDelim, , "Testing", "C:\Junk.Txt", True
MsgBox "Done"
End Sub


Hi salad, yes it does and is much simpler than I thought, although it
links all of the data to one field. Can this method handle CSVs?

Many thanks.

Keith.
I don't know. I selected a table and Save/exported it to a text file.
It prompted me if I wanted headers and if I wanted it delimited. I said
Yes to both...so I had headers and it was comma delimited. Then I did
my "linktext" sub above and I ended up with Testing with my columns like
they were from the original table. Is that what you wanted?
Sep 5 '07 #4

P: n/a
"Salad" <oi*@vinegar.comwrote in message
news:13*************@corp.supernews.com...
I ended up with Testing with my columns like they were from the original
table. Is that what you wanted?

Yes it is but it's not working for me. Not my day today. If I link to the
same file maually it works, the only difference being I have to change the
"text qualifier" property to "none". I think that's where my problem lies.

Sep 6 '07 #5

P: n/a
"Keith Wilby" <he**@there.comwrote in message
news:46********@glkas0286.greenlnk.net...
the only difference being I have to change the "text qualifier" property
to "none". I think that's where my problem lies.
Using a saved link spec solved the problem.

Sep 6 '07 #6

P: n/a

"Keith Wilby" <he**@there.comschreef in bericht news:46********@glkas0286.greenlnk.net...
"Salad" <oi*@vinegar.comwrote in message
news:13*************@corp.supernews.com...
>I ended up with Testing with my columns like they were from the original
table. Is that what you wanted?

Yes it is but it's not working for me. Not my day today. If I link to the
same file maually it works, the only difference being I have to change the
"text qualifier" property to "none". I think that's where my problem lies.
Hi Keith,

You need to look at import/export specifications.
Create one that suits your needs e.g. "importcsv" and use it like: (adapted Salad's example)
DoCmd.TransferText acLinkDelim, "importcsv" , "Testing", "C:\Junk.Txt", True

Arno R
Sep 6 '07 #7

P: n/a
"Arno R" <ar****************@planet.nlwrote in message
news:46***********************@text.nova.planet.nl ...
Hi Keith,

You need to look at import/export specifications.
Create one that suits your needs e.g. "importcsv" and use it like:
(adapted Salad's example)
DoCmd.TransferText acLinkDelim, "importcsv" , "Testing", "C:\Junk.Txt",
True
Arno R
Hi Arno,

Yes that did dawn on me but then I discovered that there was something wrong
with my text file <grrr!so now salad's code works fine. Many thanks to
you both.

Regards,
Keith.

Sep 6 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.