Hello. Access 2003.
Does someone have sample code to import a csv file using ADO, and to
either append (or create a table and then append) row by row?
Basically, I want to append rows one by one but to perform some validation
as this is done.
Thanks, Andy.
ADO import csv line by line
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
ADO import csv line by line
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: ADO import csv line by line
Try something like this:
Code: Select all
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=H:\TextFiles"
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM [Test.csv]", cnn, adOpenForwardOnly, adLockOptimistic, adCmdText
Do While Not rst.EOF
' Do something with record here
...
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set cnn = Nothing
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: ADO import csv line by line
Perfect, thanks. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.