Re: Execute Queries in VisualBasic 6.0

From: Lars-Erik Aabech (larserik_at_newsgroup.nospam)
Date: 12/17/04


Date: Fri, 17 Dec 2004 14:00:38 +0100

Hi!

Use an ADODB.Command object. I'm not sure if the Query objects in Access
corresponds to cmd.CommandType adCmdStoredProc or adCmdText (or another
type), the default is adCmdText. Then you set the parameters using the
cmd.Parameters collection, or you can pass them using an array to the
cmd.Execute() method.

Ex:

dim cn as Connection
dim cmd as Command

set cn = new Connection
cn.open...

set cmd.ActiveConnection = cn
cmd.CommandType = adCmdText ' or adCmdStoredProc
cmd.CommandText = "TheQuery"
cmd.Execute , Array(param1, param2)
' You can pass a ref to a long in the first param of the method to get
numbers of records affected

GL!

Lars-Erik

"M. R." <Ma.Riederer@t-online.de> wrote in message
news:eLDkAPD5EHA.2316@TK2MSFTNGP15.phx.gbl...
> Hi everyone,
>
> hope i can get an expert advise for my problem.
>
> I would like to open or execute Queries which are already in
> a MS-Access Database from the Visual Basic Code.
>
> The connection to the Database already exists and works for storing
> data and read data from the database tables or queries.
>
> Which commands or parameters do i need to execute a query over ADO ?
>
>
> Best regards
>
> Matthias Riederer
>
>



Relevant Pages

  • Re: Error 3265 mystery error
    ... error) when I attempt to open a recordset in an Access 2000 database ... The myConnection variable is an open ADODB connection object. ... "tblTest" is an existing table in the database. ... adOpenKeyset, adLockOptimistic, adCmdText) ...
    (microsoft.public.data.ado)
  • Re: Use query name in Open recordset statement
    ... adCmdText ... Table or SQL String ... I then split the tables out into a back end database and we ... >> actual SQL statment as opposed to the name of a query. ...
    (microsoft.public.access.queries)
  • Re: Run a script to alter a column in a table?
    ... every time we need to upgrade the Access database, ... For running the SQL command like that, I need to open the Access ... That's why I said "Run this as if it were a regular SQL ... Use the adCmdText in the Connection's Execute method: ...
    (comp.databases.ms-access)
  • Jet.OLEDB and Access 2003
    ... Database or object is read-only. ... My connection string is as follows: ... adCmdText ... Prev by Date: ...
    (microsoft.public.vb.database)
  • Re: executing stored proc from Excel
    ... urkec wrote: ... I had to set the CommandType from adCmdStoredProc to adCmdText, AND I had to do what you just said. ...
    (microsoft.public.excel.programming)