+ Reply to Thread
Results 1 to 9 of 9

Executing queries in Access from Excel

  1. #1
    Registered User
    Join Date
    02-20-2010
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2007
    Posts
    2

    Executing queries in Access from Excel

    Hi,

    I am making a tool that has as a front end an Excel workbook and as a back end an Access DB. I am storing and processing the data at the DB. All the data processing and storing is triggered by buttons in the workbook, therefore I have a set of macros that runs queries in the DB. All the queries that I run are defined at the access data base.

    Here the problem: I run the queries in the Excel macros by their names, and this sometimes works and sometimes not. Bellow a piece of my code.
    Please Login or Register  to view this content.
    --------------------------------------------------------------------------------------------------------------------------

    In the function EjecutarSQL "c" is for example an Insert query defined in the DB and named C1, thus when I want to execute this query I write EjecutarSQL("C1") in my code, and not EjecutarSQL("Insert (x1, x2, x3) into ..."). I want to keep running the queries in this way because this gives me flexibility to modify my tool without modifying the code.

    The error I sometimes get is in the line “cn.Execute c”, and the message is invalid SQL syntax.

    Any idea or suggestion is welcomed. Thanks in advance.

    Felipe99.
    Last edited by royUK; 02-21-2010 at 04:48 AM.

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Executing queries in Access from Excel

    Hi,

    Make sure in VBE Tools References Microsoft ActiveX DataObjects 2.8 or higher is checked...

    HTH

  3. #3
    Registered User
    Join Date
    02-20-2010
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Executing queries in Access from Excel

    I have review this and it is checked.

    Any other idea?

    Thanks,

    Felipe99

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Executing queries in Access from Excel

    The error would imply that the SQL itself is incorrect, rather than the code necessarily. What is the SQL in question?
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Executing queries in Access from Excel

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Added this once only,future posts that break the Forum Rules may be closed,so READ THEM
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Executing queries in Access from Excel

    In a similar vein to what the big R asked, is it always the same query that fails (and does this particular query ever work)? Also, what are you doing with the recordset produced? You don't seem to be assigning it anywhere.

    Richard
    Richard Schollar
    Microsoft MVP - Excel

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Executing queries in Access from Excel

    Surely, of the two of us, you would be the big R?

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Executing queries in Access from Excel

    The mighty big R's ...

  9. #9
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Executing queries in Access from Excel

    Quote Originally Posted by romperstomper View Post
    Surely, of the two of us, you would be the big R?
    Certainly in terms of girth and height Probably not brain power, unfortunately

+ 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