View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
SingLoke SingLoke is offline
external usenet poster
 
Posts: 4
Default Import CSV fieldname problem

I found the problem. The oringal fieldname has a "." in it (e.g.
"testing_A.1D", Access just deleted the dot while in VBA, it changed the "."
to "#".

So, when I try to apply "Select testing_A.1D from main.csv" I got an error
message. do you have any idea on how to select the "testing_A.1D" from the
csv file?

Thanks.

"RichardSchollar" wrote:

Hi SingLoke

I am unable to recreate the error you are seeing (the code works
perfectly on my machine). The only time I get that error is when the
field name (eg testing_A1D) does not match up to a field name in the
target csv file.

Hence, I suspect that although they may look the same (ie the SQL
query name and the csv file header) they differ in some way. Try
copying from your SQL string into the csv and saving the csv down, and
seeing if that makes a difference.

Hope this helps!

Richard

On 6 Feb, 07:21, SingLoke wrote:
I'm tring to import a csv file by using the following code:

Dim csvFolder As String
Dim sConnectionString As String
Dim objConn As New ADODB.Connection
Dim rs As New Recordset

csvFolder = "C:\csvdata\"
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & csvFolder & ";Extended Properties=Text;"
objConn.Open sConnectionString

SelectStr = "SELECT testing_A1D from Main.csv"
rs.Open SelectStr, objConn, adOpenDynamic

When I run the code, I got the following error message:
"No value given for one or more required parameters"

But if I try to use "Select * " I can get the data. However, I noted that
the fieldname changed to "testing_A#1D".

I also tried "SELECT testing_A#1D from Main.csv", but I got another error:
Syntax errro in date in query expression 'testing_A#1D'

Please advice how to solve the problem. Thanks