Set a reference to an external database from VBA

J

jj

Hi

I create a database (DB2.mdb) from another database (DB1.mdb), and then I
export some objekts from db1 to db2. My problem is that when I try to run
db2, it complains because it now needs the reference Microsoft DAO 3.6
object library. So I need to set the reference in DB2 from VBA in DB1.

TIA
JJ
 
6

'69 Camaro

Hi, JJ.
it complains because it now needs the reference Microsoft DAO 3.6 object
library. So I need to set the reference in DB2 from VBA in DB1.

Do you mean set the reference manually using the References dialog window
from the VBA code window (VB Editor), or set the reference via VBA code? If
it's manual, then please see the following Web page for a link to Tom
Wickerath's article, "ADO and DAO Library References in Access Databases":

http://www.Access.QBuilt.com/html/articles.html

If it's via code, then try: (watch out for word wrap, as the AddFromFile
function should be all one line)

Public Sub addLibRef()

On Error GoTo ErrHandler

Dim accApp As New Access.Application

accApp.OpenCurrentDatabase "C:\Work\DB2.mdb", True
accApp.References.AddFromFile "C:\Program Files\Common Files\Microsoft
Shared\DAO\dao360.dll"
accApp.RunCommand acCmdCompileAllModules

CleanUp:

accApp.Quit
Set accApp = Nothing

Exit Sub

ErrHandler:

MsgBox "Error in addLibRef( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp

End Sub


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top