yiapap
asked on
Remove MS Access Missing References though VBA
Is there a way to remove broken references in an Access application through VBA?
For example,
An MDB has a reference to Outlook 2003 lib (msoutl.olb).
When run in an MSOffice 2000 environment this reference is broken ("MISSNG:...") because the path to msoutl.olb is different in Office9 (2000).
Is there a way to either:
1. Update the FullPath of the missing reference (.FullPath is read-only)
2. Remove the missing reference and insert a new one (.Remove method of References collection fails with Run-time error -2147319779 (Object library not registered) )
Please note that I want to do this from VBA or a VB.exe using the Access.Application object, NOT through user interaction via the references window.
PS. To reproduce the behaviour, place a reference to Microsoft Office 11.0 Object Library in an mdb, rename msoutl.olb found in C:\Program Files\Microsoft Office\OFFICE11\MSOUTL.OLB (Replace OFFICE11 with your Office version) and run the MDB. The reference should appear as missing and the code (any code using for example Left$,Right$) will break..
Thanks in advance for your time
For example,
An MDB has a reference to Outlook 2003 lib (msoutl.olb).
When run in an MSOffice 2000 environment this reference is broken ("MISSNG:...") because the path to msoutl.olb is different in Office9 (2000).
Is there a way to either:
1. Update the FullPath of the missing reference (.FullPath is read-only)
2. Remove the missing reference and insert a new one (.Remove method of References collection fails with Run-time error -2147319779 (Object library not registered) )
Please note that I want to do this from VBA or a VB.exe using the Access.Application object, NOT through user interaction via the references window.
PS. To reproduce the behaviour, place a reference to Microsoft Office 11.0 Object Library in an mdb, rename msoutl.olb found in C:\Program Files\Microsoft Office\OFFICE11\MSOUTL.OLB
Thanks in advance for your time
Why don't you just use late binding?
ASKER
Late binding as in CreateObject?
ASKER
Correction in my PS.
To reproduce the behaviour you need to move the MDB to an Office 2000 environment. The example I'm giving requires different handling.
To reproduce the behaviour you need to move the MDB to an Office 2000 environment. The example I'm giving requires different handling.
Using a late binding in your code
ie
dim a
set a = createobject("Access.appli cation")
In this case, even the program will run slower but it is independent on what version the user loaded on their machine
ie
dim a
set a = createobject("Access.appli
In this case, even the program will run slower but it is independent on what version the user loaded on their machine
ASKER
The problem with that is that I will not have access to the properties and methods of the created objects in the VB editor. I will only be able to use the object browser to remember them and their parameters.
I'm also not very sure as to how some pieces of code will "react". In the Outlook example, there's code that manipulates dozens of emails amongst potentially thousands in the user's Inbox. The code is already very time consuming although I have made any and all imaginable optimisations!
In any case, I'll try your suggestion, by programming using early binding and changing to late binding before deploying.
Thanks for the help.
I will leave this Q open for a few more days, just in case someone comes up with the answer to the actual question.
Thanks again,
Yiannis
I'm also not very sure as to how some pieces of code will "react". In the Outlook example, there's code that manipulates dozens of emails amongst potentially thousands in the user's Inbox. The code is already very time consuming although I have made any and all imaginable optimisations!
In any case, I'll try your suggestion, by programming using early binding and changing to late binding before deploying.
Thanks for the help.
I will leave this Q open for a few more days, just in case someone comes up with the answer to the actual question.
Thanks again,
Yiannis
ASKER
There are some problem with late binding.
Some of the classes like Outlook.NameSpace and Outlook.ContactItem cannot be created through the CreateObject method.
In the following function where the functions resulting type is now Variant for example:
Public Function GetContact(ByVal sID As String) ' As Outlook.ContactItem
....
Set ns = ol.GetNamespace("MAPI")
Set fdContacts = ns.GetDefaultFolder(olFold erContacts )
Set ContactItems = fdContacts.Items.Restrict( scriteria)
For Each lContact In ContactItems
If Trim(UCase(lContact.User1) ) = sID Then
Set GetContact = lContact
GoTo Exit_Point:
End If
...
The line Set GetContact=lContact does NOT return an ContactItem.
Although the description of GetContact is Variant/Object/ContactItem I cannot use any of the class properties/methods.
In contrast the line:
Set GetContact = fdContacts.Items.Add
works like a charm!
Thanks again.
Some of the classes like Outlook.NameSpace and Outlook.ContactItem cannot be created through the CreateObject method.
In the following function where the functions resulting type is now Variant for example:
Public Function GetContact(ByVal sID As String) ' As Outlook.ContactItem
....
Set ns = ol.GetNamespace("MAPI")
Set fdContacts = ns.GetDefaultFolder(olFold
Set ContactItems = fdContacts.Items.Restrict(
For Each lContact In ContactItems
If Trim(UCase(lContact.User1)
Set GetContact = lContact
GoTo Exit_Point:
End If
...
The line Set GetContact=lContact does NOT return an ContactItem.
Although the description of GetContact is Variant/Object/ContactItem
In contrast the line:
Set GetContact = fdContacts.Items.Add
works like a charm!
Thanks again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.