Programmatically Importing References in Access 2000

  • Thread starter Thread starter Michelle
  • Start date Start date
M

Michelle

Hello All-
I am creating a utility that allows users to restore
corrupt mdb files. To accomplish this, I create a new,
blank database and import all objects from the corrupted
database to the blank database. All this is done in vba
code. The only problem with this is that references are
not copied with the objects that require them. Does
anyone know how to programatically import references from
one mdb file to another?
Thank you in advance.
 
I don't believe it's possible to import references.

What you can try to do is determine what the references in the other
database are, using code like the following:

Sub ListOtherReferences(OtherDatabase As String)
Dim appCurr As Access.Application
Dim refCurr As Reference

Set appCurr = New Access.Application
appCurr.OpenCurrentDatabase OtherDatabase

For Each refCurr In appCurr.References
Debug.Print refCurr.Name & ": " & refCurr.FullPath & ", " &
refCurr.GUID
Next

appCurr.CloseCurrentDatabase
Set appCurr = Nothing

End Sub

Once you know each of the references that should be there, use the
AddFromFile (or AddFromGUID) method of the References collection to
establish the correct references in the new database.
 
Thanks, but I found a way to do it. Here it is in case
anyone else is interested:

Dim ac as Access.Application
Set ac = new Access.Application
ac.OpenCurrentDatabase (strSource)

Dim bc As Access.Application
Set bc = New Access.Application
bc.OpenCurrentDatabase (strDestination)

Dim i As Integer
Dim j As Integer
Dim blnRefMatch As Boolean
blnRefMatch = False
For i = 1 To ac.References.Count
For j = 1 To bc.References.Count
'make sure the destination db does not already
have the specified reference - an error occurs if it does
and you try to set the reference again
If ac.References.Item(i).Name = bc.References.Item
(j).Name Then
blnRefMatch = True
Exit For
End If
Next
If blnRefMatch = False Then
bc.References.AddFromFile (ac.References.Item
(i).FullPath)
Else
blnRefMatch = False
End If
Next

ac.Quit
bc.Quit
Set ac = Nothing
Set bc = Nothing
 
Sorry to seem pedantic, but that doesn't import the references. It's doing
exactly what I suggested, and using the AddFromFile method of the References
collection!
 
I guess it is as close to "importing" as we will get. I
like your function for listing the references. It was
important that my solution be as dynamic and reuseable as
possible since it will be used over and over by users
recovering corrupt mdb's. Thanks for your help.
 
Back
Top