VBA To Fix Broken References

M

Mike O'Brien

Hello Group,

I would like to fix broken references through code. I
have tried a variety of methods, but cannot seem to grab
hold of the broken references to delete / recreate them.

The basic problem is this: I have msadox.dll with version
2.7, and I create a database with VBA within, then install
it on someone's computer who only has ADOX 2.5. The
broken reference won't allow the db to compile / work.
The target computer users won't have the technical
knowledge to use Tools -> References, clear the box, etc,
and I don't know who's computer this will eventually be
installed on (so I can't do it myself).

The code is below, and gets stopped on 'If ((ref.Name
= "VBA") Or (ref.Name = "Access")) Then' because it cannot
determine the property of the Name. Even moving the line
to 'appaccess.References.Remove ref' creates a run-time
error (Num: -2147319779, Desc: Object library not
registered)

Any help would be greatly appreciated.

Thanks.

Mike.

Function RemoveAndSetReferences()
Dim strDB As String
Dim strFile As String
Dim ref As Reference
Dim appAccess As New Access.Application

' REMOVE EXISTING REFERENCES
appAccess.OpenCurrentDatabase "C:\Documents and
Settings\mowalker\My Documents\Databases\CRM.mdb"
For Each ref In appAccess.References
If ((ref.Name = "VBA") Or (ref.Name = "Access"))
Then
Else
appAccess.References.Remove ref
End If
Next ref

' SET UP REFERENCES
' OLE AUTOMATION
appAccess.References.AddFromFile "C:\WINNT\System32
\stdole2.tlb"
' ADODB 2.1
appAccess.References.AddFromFile "C:\Program
Files\Common Files\System\ado\msado21.tlb"
' ADOX 2.5
appAccess.References.AddFromFile "C:\Program
Files\Common Files\System\ado\msadox.dll"
End Function
 
P

Paul Overway

If you are distributing an MDE, broken references cannot be fixed. The best
solution in this case is to use Late Binding instead of a reference. If you
are distributing an MDB, Wayne's suggestion may be helpful, although it will
require that your end-user install an add-in. To fix broken references
yourself, you must have startup code that checks references before ANY other
code runs in your app. A good article on this topic can be found at:

http://www.trigeminal.com/usenet/usenet026.asp?1033

Paul Overway
Logico Solutions, LLC
www.logico-solutions.com
 
M

Mike O'Brien

Thank you both Paul and Wayne for your suggestions. Looks
like I'll be ramping up on reading the registry from
Access.

Mike.
 

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