+ Reply to Thread
Results 1 to 2 of 2

Use same ADO library again

Hybrid View

  1. #1
    Registered User
    Join Date
    09-24-2008
    Location
    Sweden
    Posts
    10

    Use same ADO library again

    Hi,

    I've a project (file) that uses ADO 2.7 library, when I start a new project (file) I'm not allowed to choose this reference. Am I only allowed to connect one library to one project? If so, how can I connect my new file with this other project?

    Hope you understand my question...

    BR,

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    What do you mean by choose?

    I do it all the time. Maybe you did not close a connection. If you post some code, we may be able to see what is wrong.
    e.g.
    Sub ADO()
    '   Set Reference in Tools to: Microsoft ActiveX Data Objects 2.x Library
        Dim DBFullName As String
        Dim Cnct As String, Src As String
        Dim Connection As ADODB.Connection
        Dim Recordset As ADODB.Recordset
        Dim Col As Integer, Row As Long, s As String
        
    '   Database information
        DBFullName = ActiveWorkbook.Path & "\NWind2003.mdb"
    'Exit?
        If Dir(DBFullName) = "" Then Exit Sub
    
    'Clear any existing data from activesheet
       Cells.Clear
    
    '   Open the connection
        Set Connection = New ADODB.Connection
        Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
        Cnct = Cnct & "Data Source=" & DBFullName & ";"
        Connection.Open ConnectionString:=Cnct
        
    '   Create RecordSet
        Set Recordset = New ADODB.Recordset
    '   Record locking
      Recordset.CursorType = adOpenKeyset
      Recordset.LockType = adLockOptimistic
        
        With Recordset
    '       Filter
            'Src = "SELECT * FROM Products WHERE ProductName = 'Watch' "
            'Src = Src & "and CategoryID = 30"
            Src = "SELECT Orders.CustomerID, Orders.OrderDate " & _
              "FROM Orders " & _
              "WHERE (((Orders.OrderDate) " & _
              "Between #8/1/1994# and #8/30/1994#))"
            Recordset.Open Source:=Src, ActiveConnection:=Connection
    
    '       Write the field names
            For Col = 0 To .Fields.Count - 1
               Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
            Next Col
            
    '       Write the recordset
            Range("A1").Offset(1, 0).CopyFromRecordset Recordset
            Dim a As Variant
            .MoveFirst
            a = Recordset.GetRows
            MsgBox LBound(a), , UBound(a)
            MsgBox a(0), , a(1)
    
            If .RecordCount < 1 Then GoTo endnow
            .MoveFirst
            For Row = 0 To (.RecordCount - 1)
              'Debug.Print CStr(.Fields(Row).Value)
              .MoveNext
            Next Row
      End With
    endnow:
        Set Recordset = Nothing
        Connection.Close
        Set Connection = Nothing
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Ho do I upload an Excel WorkBook to a SharePoint Document Library using VBA
    By mirror1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-28-2008, 11:24 PM
  2. Reference library for .net method
    By tg000001 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-14-2008, 06:47 AM
  3. Adding library references with code -> error 1004
    By cyc1120 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2008, 12:29 PM
  4. Microsoft Visual Basic For Applications Extensibility Library
    By DCSwearingen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2006, 03:52 PM
  5. data library help
    By owaring in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-23-2006, 08:15 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1