Results 1 to 4 of 4

Thread: Run Query in Access from VBA

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    16

    Run Query in Access from VBA

    Does anyone know if its possible to execute an Update query made in Access from VBA code. Im using ADODB.Recordset but I can only retrieve data from access select queries, I want to update the db from VBA using an update query in access.

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Run Query in Access from VBA

    VB Code:
    1. ADODB.Execute
    ?
    if you fail to plan, you plan to fail

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    16

    Re: Run Query in Access from VBA

    Im writing in Excel VBA, there is no ADODB.Execute command there.

    My code is like this:

    szConnect = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=H:\TIDREDOV.mdb;"

    Set objCommand = New ADODB.Command
    objCommand.ActiveConnection = szConnect

    objCommand.CommandText = "UPDATE(...)SET....
    objCommand.Execute RecordsAffected:=lRecordsAffected,
    Options:=adCmdText Or adExecuteNoRecords

    Which works fine, however I want to use a stored update query in Access instead of writing the query in the command text. I know how to retrieve data using a stored query(called Test), like this:

    Set rsGetData = New ADODB.Recordset
    rsGetData.Open "[Test]", szConnect, adOpenForwardOnly, adLockReadOnly, adCmdTable

    I wonder if its possible to execute a stored update query and how u do that.

    Best regards

    Bjso

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Run Query in Access from VBA

    Uh I think you need to execute it (some what like you posted and was previously posted?)

    Your object you declared is the ADODB ...

    The Stored procedure, I haven't run before but should be the same as a query.

    You may need to supply parameters though, in which case you'll need to read up on how to do this or see is szlamany can point you in the right direction.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width