kbutler
asked on
Reference remover code not working
I have this code that runs at startup to check references and it has been working fine. If for example they are missing the email files the code removes the reference. But today one of the systems had a reference to "shappmgrp 1.0 Type Library". The reference was missing when the system started and I got "Runtime Error 48 Error Loading DLL". As soon as I removed the reference (by opening the reference on tools) then the system ran fine. Why has the code been removing missing references but fails to remove this one?
Public Function Referencelist()
Dim ref As Reference
For Each ref In References
If ref.IsBroken = True Then
References.Remove ref
End If
Next ref
End Function
Public Function Referencelist()
Dim ref As Reference
For Each ref In References
If ref.IsBroken = True Then
References.Remove ref
End If
Next ref
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi kbutler,
Try this code:
Public Sub CheckMissingReferences()
Dim loRef As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String
Dim bBroke As Boolean
On Error Resume Next
Err.Clear
'Count the number of references in the database
intCount = Access.References.Count
'Loop through each reference in the database and determine if the reference is broken.
'If it is broken, remove the Reference and add it back.
For intX = intCount To 1 Step -1
Set loRef = Access.References(intX)
Debug.Print loRef.Name, loRef.FullPath
'Dont do Access
With loRef
If .IsBroken = True Then
MsgBox loRef.Name & " is broken" & vbCrLf & loRef.FullPath, vbInformation, "Check"
End If
End With
Next
Set loRef = Nothing
Exit Sub
rrError:
MsgBox "Error " & Err.Number & " trapped." & vbCrLf & Err.Description, vbCritical, "Check"
End Sub
Hope this helps
Jaffer
Try this code:
Public Sub CheckMissingReferences()
Dim loRef As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String
Dim bBroke As Boolean
On Error Resume Next
Err.Clear
'Count the number of references in the database
intCount = Access.References.Count
'Loop through each reference in the database and determine if the reference is broken.
'If it is broken, remove the Reference and add it back.
For intX = intCount To 1 Step -1
Set loRef = Access.References(intX)
Debug.Print loRef.Name, loRef.FullPath
'Dont do Access
With loRef
If .IsBroken = True Then
MsgBox loRef.Name & " is broken" & vbCrLf & loRef.FullPath, vbInformation, "Check"
End If
End With
Next
Set loRef = Nothing
Exit Sub
rrError:
MsgBox "Error " & Err.Number & " trapped." & vbCrLf & Err.Description, vbCritical, "Check"
End Sub
Hope this helps
Jaffer
ASKER
PendragonZero
Yes I did run the function. Actually the function that is in production is much larger than what i showed here, but when the user reported the probem I went in and removed everything execpt for what is listed above and put in debug mode to try and see what is happening. I still got the error.
nyckidd
Yes I get the message evertime on the user machine. I can not recreate the error on any of my development machines. When I remove MSOutl.olb (which is the reference) Windows in nice enough to just creates another one. I even tried removing everything that was MSoutl.* and somehow it still rebuilds it.
I think you might be right on the registry issue, I found it strange that all of my other user machines work fine with the reference removal code.
In fact I don't need the reference at all for my application. I just don't like surprises, and I thought the code would take care of all missing references.
jaffer
It looks to me like the meat of your code is the same as mine, that is the reference object. I get the error on ref.isbroken. I use autoexec to call the reference function and I have the function in a module with no other code. I did that to stop reference errors before the code could remove them. Why do you think your code will work when mine faild. I am happy to try it but it is a fair amount of effort to get to the user machine and do a test.
Yes I did run the function. Actually the function that is in production is much larger than what i showed here, but when the user reported the probem I went in and removed everything execpt for what is listed above and put in debug mode to try and see what is happening. I still got the error.
nyckidd
Yes I get the message evertime on the user machine. I can not recreate the error on any of my development machines. When I remove MSOutl.olb (which is the reference) Windows in nice enough to just creates another one. I even tried removing everything that was MSoutl.* and somehow it still rebuilds it.
I think you might be right on the registry issue, I found it strange that all of my other user machines work fine with the reference removal code.
In fact I don't need the reference at all for my application. I just don't like surprises, and I thought the code would take care of all missing references.
jaffer
It looks to me like the meat of your code is the same as mine, that is the reference object. I get the error on ref.isbroken. I use autoexec to call the reference function and I have the function in a module with no other code. I did that to stop reference errors before the code could remove them. Why do you think your code will work when mine faild. I am happy to try it but it is a fair amount of effort to get to the user machine and do a test.
kbutler-
In your original question, you mentioned that the problem reference was the Shappmgrp Type Library. Have you more recently discovered that it's not that particular reference that's causing the problem? MSOutl.olb is the Outlook Type Library from what I can recall (don't have outlook installed on present machine so I can't confirm). Is outlook used on the problem machine, and if so, is Outlook working without any noticeable problem?
I'm wondering if the MSOutl.olb file needs to be re-registered (using RegSvr32 (path to)\msoutl.olb ). The fact that your getting the error ON the ref.isbroken statement seems to further support the idea that something might be hosed on that machine, and if Windows File Protection is restoring those files after you delete them, then the copies it has in it's cache of protected files might also be corrupt. (this is all off the top of my head, so I could be completely off base..)
Doesn't Office Setup have some facility for doing a repair on an installation? Maybe running that would fix it.
I'll give this some more thought and research if I have the time and post back if I come up with anything else.
In your original question, you mentioned that the problem reference was the Shappmgrp Type Library. Have you more recently discovered that it's not that particular reference that's causing the problem? MSOutl.olb is the Outlook Type Library from what I can recall (don't have outlook installed on present machine so I can't confirm). Is outlook used on the problem machine, and if so, is Outlook working without any noticeable problem?
I'm wondering if the MSOutl.olb file needs to be re-registered (using RegSvr32 (path to)\msoutl.olb ). The fact that your getting the error ON the ref.isbroken statement seems to further support the idea that something might be hosed on that machine, and if Windows File Protection is restoring those files after you delete them, then the copies it has in it's cache of protected files might also be corrupt. (this is all off the top of my head, so I could be completely off base..)
Doesn't Office Setup have some facility for doing a repair on an installation? Maybe running that would fix it.
I'll give this some more thought and research if I have the time and post back if I come up with anything else.
ASKER
My mistake, i was also using MSOutl.olb for testing. The problem is with shappmgrp which is appwiz.cpl.
maybe there was gap where the reference slipped in
also, if you have a set list references that you use;
you could just remove references that are not in your set..