Pergunta

I have an Access 2010 accdb database, which I converted from an Access 2003 mdb database.
When I ran the following code in Access 2003, it would create a database that, by default, had a reference to ADODB - "Microsoft ActiveX Data Objects 2.5 Library" (msado25.tlb).

Set dbNewApp = Application.DBEngine.CreateDatabase("Test.mdb", dbLangGeneral)

If I run the following (similar) code in Access 2010, it successfully creates an accdb database, but there is no reference to the ADODB library as above.

Set dbNewApp = Application.DBEngine.CreateDatabase("Test.accdb", dbLangGeneral)

According to the following link, the default references included when you create a new database has changed between DAO and ADODB and back again over the various versions of Access: http://allenbrowne.com/ser-38.html

So I need my newly created database to have a reference to ADODB.

I know how to change the references of the current db...

Set refNew = References.AddFromGuid("{00000205-0000-0010-8000-00AA006D2EA4}", 2, 5)

But how do I do this to another access database that I just created with DBEngine.CreateDatabase?

Foi útil?

Solução

Once you have created the database, it should be possible to open it and add reference:

Sub CreateDB()
Dim acApp As Access.Application
Dim dppath As String

    dbpath = "z:\docs\newmsmdb.mdb"
    ''http://msdn.microsoft.com/en-us/library/office/ff835033.aspx
    CreateDatabase dbpath, dbLangGeneral, dbVersion40

    ''http://msdn.microsoft.com/en-us/library/office/aa140509(v=office.10).aspx
    Set acApp = New Access.Application
    With acApp
        .OpenCurrentDatabase dbpath
        acApp.References.AddFromFile _
             "c:\program files\common files\system\ado\msado15.dll"
    End With
End Sub
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top