Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Mar 2001
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default to the Current Database when using ADO (Access 2002)

    I'm just learning to convert over to ADO from DAO. I want to somehow tell ADO to use the current db. But I don't want to use DAO 3.6 Object Library and dim a database and set it to currentDB. Does anyone know how to specify the current DB for ADO?

    ps: It's been hard to find truly helpful simple code samples, syntax, and explainations for ADO. Any advice would be appreciated. Thanks <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Default to the Current Database when using ADO (Access 2002)

    You can't do exactly the same thing with ADO, but you can reference the CurrentProject, which is roughly the same as CurrentDb ... almost. The trouble is that there *is* no database object in ADO, so you'll have to explain what you're trying to do in order to get the help you need.
    Charlotte

  3. #3
    New Lounger
    Join Date
    Mar 2001
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Default to the Current Database when using ADO (Access 2002)

    OK, all I want to do is manipulate tables in the current MDB using ADO only, no DAO library stuff.

    When I used DAO I specified the database and tables this way. No explicit reference to the MDB:

    Dim db As Database
    Dim rst As Recordset
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("tblXXXX", dbOpenTable)
    [ Use DAO to work with the recordset ...]

    How do I do the equivalent(or whatever will work) to be able to use ADO in the open MDB, without using the DAO library ? All the examples I find are client-server or odbc type connections, but all I want to do is simple coding within a single MDB.

    Well, i hope this is clearer for you, but I get the feeling i should have had another cup of coffee before i wrote this. Thanks

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Default to the Current Database when using ADO (Access 2002)

    It isn't as simple in ADO because there are so many different ways to do the same (or nearly the same) thing. If all you want to do is open a recordset, that isn't the same thing as manipulating the tables, so again, you have to ask specific questions to get help.

    There are actually multiple ways to open a recordset. You can open one based on CurrentProject.ActiveConnection, or you can specify a connection, or you can open a command object and open the recordset on that, or you can create a recordset and open it later .... It all depends on what you want to do. Manipulating objects like tables in ADO is more complicated because tables live in the Catalog object, which is part of the ADOX library. On the other hand, the application itself has collections like AllTables. This is from on-line help:<pre>Sub AllTables()
    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentData
    ' Search for open AccessObject objects in AllTables collection.
    For Each obj In dbs.AllTables
    If obj.IsLoaded = TRUE then
    ' Print name of obj.
    Debug.Print obj.Name
    End If
    Next obj
    End Sub</pre>


    There's a white paper on the Microsoft site on migrating from DAO to ADO. I would suggest you download and read it and then get yourself a couple of books specific to Access and ADO. You might use a Lounge Search on this forum for references to ADO and Books to locate some recommendations.
    Charlotte

Posting Permissions

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