Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    3

    Unanswered: OpenRowset and ADO

    Hi....

    I'm trying to query an Excel spreadsheet in VB using ADO. When I run the following query in SQL Query Analyzer it works fine, but when I put the code within a VB Function, I get a syntax error in FROM clause error from the Microsoft ODBC Excel Driver. Any ideas what I could be doing wrong. Here's the code :

    Query (this works fine in SQL Query Analyzer):
    Select * from OPENROWSET
    ('MSDASQL',
    'Driver=Microsoft Excel Driver (*.xls);DBQ=C:\myFiles\0486-52.xls',
    'SELECT * FROM [0486-52$B8:P8]')


    VB Code:
    Set rs = New ADODB.Recordset
    Set cn = New ADODB.Connection
    cn.CursorLocation = adUseClient
    cn.Open "Provider=MSDASQL;Driver=Microsoft Excel Driver *.xls);DBQ=C:\myFiles\0486-52.xls"
    rs.Open sSQL, cn, adOpenStatic


    Any help is highly appreciated. THanks.

  2. #2
    Join Date
    Aug 2003
    Location
    Andover, MA
    Posts
    256
    You left out the contents of sSQL. Are you using OpenRowset in that query as well?
    -bpd

  3. #3
    Join Date
    Aug 2003
    Location
    Andover, MA
    Posts
    256
    Oh, nevermind.
    -bpd

  4. #4
    Join Date
    Sep 2003
    Posts
    3
    Sorry, Didn't include sSQL. It's the same query as the one directly above that I ran in SQL Query analyzer. THanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •