View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Loane Sharp Loane Sharp is offline
external usenet poster
 
Posts: 28
Default list of extended properties for use with ADO connection strings

Hi there

Please would you comment on the two items below. The first piece of code
works OK: all the records make it from the CSV file into the active Excel
worksheet with the correct structure, so I suppose I've got the basic
activity more-or-less right.

(1)

Set cnSource = New ADODB.Connection
Set rsData = New ADODB.Recordset
strConnect = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\PathToCSVFile\;" & _
"Extended Properties=""Text;HDR=Yes;FMT=Delimited"""
strSQL = "SELECT * FROM SourceCSVFile.csv"
rsData.Open strSQL, cnSource, adOpenStatic, adLockOptimistic, adCmdText
Activesheet.Range("A1").CopyFromRecordset rsData
Set rsData = Nothing
Set cnSource = Nothing

(2)

However, my objective is to insert the data from the CSV file into a (new)
table in an (existing) Access database, which I attempt to do as follows.

Set cnSource = New ADODB.Connection
strConnect = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\PathToCSVFile\;" & _
"Extended Properties=""Text;HDR=Yes;FMT=Delimited"""
cnSource.Open strConnect
strSQL = "SELECT * INTO NewTable IN C:\NewAccessDB.mdb FROM
SourceCSVFile.csv"
cnSource.Execute strSQL
Set cnSource = Nothing

P.S. My dataset is actually pipe delimited (|), but I'm presuming that this
will be straightforward ... once I've got the above right! -- ie. I will
create a file "schema.ini" containing the following two lines, and save the
"schema.ini" file in the same folder as the SourceCSVFile.csv:

[SourceCSVFile.csv]
Format=Delimited(|)

Please help ...

Best regards
Loane