dcsimg
Results 1 to 4 of 4
  1. #1

    Thread Starter
    Registered User
    Join Date
    Dec 2017
    Posts
    2

    Using ADODB to open MS Access query

    Please help. I want to open a predefined query in MDB using ADODB in vb6. HOw can i do that?


    CmdQry.CommandType = adCmdStoredProc
    CmdQry.CommandText = "qry_control_totals_validation_lnosclt" 'this is a query in MDB

    Set rsQry = CmdQry.Execute
    If (rsQry.RecordCount = 0) Then

  2. #2
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,083

    Re: Using ADODB to open MS Access query

    Hi,

    this is one way to do it.

    Code:
    Private Sub Command1_Click()
     Dim cnn As New ADODB.Connection
       Dim rst As New ADODB.Recordset
       Dim fld As ADODB.Field
    
       'connection
       cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=D:\NorthWind.mdb;"
    
       ' Open query
       rst.Open "[qryCustOrders]", _
          cnn, adOpenForwardOnly, adLockReadOnly, adCmdStoredProc
    
    
       ' debug window
       Do Until rst.EOF
          For Each fld In rst.Fields
             Debug.Print fld.Value & ";";
          Next
          Debug.Print
          rst.MoveNext
       Loop
    
       ' Close the recordset
       rst.Close
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,330

    Re: Using ADODB to open MS Access query

    Rather than using recordcount=0 would be best to check the EOF.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,676

    Re: Using ADODB to open MS Access query

    CmdQry.CommandType = adCmdStoredProc -- wrong command type ... you should have used adCmdTable or adCmdText .... a query is a query or a view, not a stored proc.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width