Quantcast
Viewing all articles
Browse latest Browse all 3755

Excel ODBC Query Help

I am trying to query an Excel file using the ODBC driver. I was hoping someone here might know the correct syntax to query by column name using a cell range. I have the query working fine by cell range using select * and IdxField but I was really trying to figure out how to get the data by field names.

This works fine:

strQuery = "SELECT * " +_
"FROM [Sheet1$A1:D6]"

if rs <> nil then
  while (not RS.EOF)     
    A.Add(rs.IdxField(1).StringValue)
    B.Add(rs.IdxField(2).StringValue)
    C.Add(rs.IdxField(3).StringValue)
    D.Add(rs.IdxField(4).StringValue)       
    rs.MoveNext
  wend
end

But this does not: (The driver complains it needs 4 more parameters, I am assuming one cell range for each column, but what is the syntax for that?)

strQuery = "SELECT [A], [B], [C], [D] " +_
"FROM [Sheet1$A1:D6]"

if rs <> nil then
  while (not RS.EOF)    
    A.Add(rs.Field("A").StringValue)
    B.Add(rs.Field("B").StringValue)
    C.Add(rs.Field("C").StringValue)
    D.Add(rs.Field("D").StringValue)    
    rs.MoveNext
  wend
end

Any suggestions? Thanks.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 3755

Trending Articles