Results 1 to 4 of 4

Thread: execute Access query/stored procedure within VB6?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    I need to be able to execute an Access query from my VB6 application. Access
    will not be installed on the end user machine but the query will already be
    in the .mdb file.

    There is a reason why I need to do this as opposed to running an SQL statement
    in VB6 but I don't want to steer this post away from my initial question so I'll
    leave out the reason..

    Anyway, it seems that this can be possible because if you use the ADO control
    to connect to an Access database, it shows the Query's as "Stored Procedures", but
    I just don't know how to go about actually executing a query..

    The query will not return any data, it is strictly an "action" query (such as Append,
    Make table, etc..) so I don't need to show the results of the query...

    Remember again that Access will not be installed so I don't want to use any Access objects
    in my code..

    Dan

  2. #2
    Lively Member
    Join Date
    Apr 2000
    Location
    Rafaela (Argentine)
    Posts
    107
    Try this:

    Code:
    Dim dbsDB As Database, qryAction As QueryDef
    
    Set dbsDB = DBEngine.OpenDatabase(...)
    Set qryAction = dbsDB.QueryDefs("Query Name")
    ' You can set query parameter values here, using
    ' qryAction.Parameters("Parameter Name") = value
    qryAction.Execute dbFailOnError
    Hope it helps!

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Is that using ADO? QueryDef does not seem to be a valid option (it doesn't pop up as one of the options..)

    Any ideas?

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you want to use ADO, then you can do something like this:
    Code:
    Dim cn As New ADO.Connection
    
    
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDB.mdb"
    cn.Execute "YourQueryName"

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