+ Reply to Thread
Results 1 to 3 of 3

Running an SQL statement into Access from Excel

  1. #1
    Registered User
    Join Date
    05-11-2007
    Posts
    22

    Running an SQL statement into Access from Excel

    Hello everyone,

    I'm trying to run an SQL statement into an Access database from Excel. Here is the code I have so far:

    Please Login or Register  to view this content.
    The following code runs perfectly fine. The recordset comes back with the statement results. However, when I try to put a 'Where' clause into the SQL statement like so:

    Please Login or Register  to view this content.
    ... the whole thing blows up and gives me an Automation Error and an Unspecified Error. The field names are all spelled correctly. The connection and cursor types seem fine as well since it returns results WITHOUT the 'Where' clause. Anyone have any ideas??? Any feedback would be greatly appreciated.

  2. #2
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    You may need a line break in your strSql between the ' select * from Yield ' and the ' where Selection = 'EPI' '.

    Try turning on the macro recorder then going through 'Data' - 'Get External Data' - 'New Database Query' and see how that SQL statement is recorded.

    HTH

  3. #3
    Registered User
    Join Date
    05-11-2007
    Posts
    22

    Didn't work

    Looks like that wasn't the problem, but a buddy of mine managed to figure it out. Apparently, the code didn't like the field name 'Section'. Not sure why, but I changed the field name from 'Section' to 'Type' and it works great. Thanks anyway for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1