Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2006
    Posts
    11

    Unanswered: Executing queries...

    HI,

    I have previously used DAO when coding in VBA, and am starting to use a bit of ADO, and my question concerns executing a query.

    What is the equivalent line of code in ADO for the following DAO line where dbs in my currentdb(), and qdf is defined as a DAO querydef:

    set qdf = dbs.querydefs ("MY_QUERY")
    qdf.execute.

    Or do I have to execute the query as in line SQL statements using
    adoCONNECTION.EXECUTE "INSERT INTO etc............"

    Thanks

  2. #2
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    If you're programming now in ADO, remove the DAO reference in the DAO.QueryDef dimension. In fact, you don't need to set the query at all. Simply use the command
    Code:
    DoCmd.OpenQuery("My_Query")
    to run the action query.

    Sam

  3. #3
    Join Date
    Oct 2006
    Posts
    11
    oki doki, that's simple enough......cheers

  4. #4
    Join Date
    Sep 2006
    Posts
    265
    I would also

    DoCmd.Close acQuery, "My_Query" afterwards.

    Simon

  5. #5
    Join Date
    Oct 2006
    Posts
    11
    ok thanks....

  6. #6
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    An ADO equivalent of

    set qdf = dbs.querydefs ("MY_QUERY")
    qdf.execute

    Might be for instance

    TheConnection.Execute("MY_QUERY", , adCmdStoredProc + adExecuteNoRecords)

    assuming you have a valid ADO connection object (TheConnection).

    adCmdStoredProc -> stored query
    adExecuteNoRecords -> no recordset is returned (faster, for action queries)

    For parameterized queries, you'd probably need the Command object, and resolve the parameters. For some info, take a look at the Execute method of the command and connection object

    Execute Method (ADO Command)
    http://msdn2.microsoft.com/en-us/library/ms681559.aspx

    Execute Method (ADO Connection)
    http://msdn2.microsoft.com/en-us/library/ms675023.aspx

    Edit: but if you're only working with Jet tables ("Access tables"), there's no point in switching to ADO, just continue to use DAO.
    Roy-Vidar

  7. #7
    Join Date
    Oct 2006
    Posts
    11
    Thanks very much for your help.......I'll give that a go

    cheers

Posting Permissions

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