Hi
I am trying to check if there is any broken references when access starts as the reference changes in different version of Access.
The code works through ok but it does not remove the missing/broken references. When I debug nothing is shown it’s just blank in the debug.print.
Any help and advice would be much appreciated'
Thank you in advance
I am trying to check if there is any broken references when access starts as the reference changes in different version of Access.
The code works through ok but it does not remove the missing/broken references. When I debug nothing is shown it’s just blank in the debug.print.
Any help and advice would be much appreciated'
Code:
Sub AddReference()
' To add a reference to the project using the GUID for the
'reference library
Dim strGUID As String, theRef As Reference, i As Long
Dim test As Boolean
Update the GUID you need below.
strGUID = "{00020813-0000-0000-C000-000000000046}" 'Excel Object library
'Set to continue in case of error
On Error Resume Next
'Remove any missing references
For i = Access.References.Count To 1 Step -1
Set theRef = Access.References.Item(i)
If theRef.IsBroken = True Then
Access.References.Remove theRef
Debug.Print theRef.Name
Debug.Print "GUID: " & theRef
End If
Next i
'Clear any errors so that error trapping for GUID additions can be evaluated
Err.Clear
'Add the reference
'unfortunately the add ref below produces error if ran in debug mode in first run:
'ERROR: can't enter break mode at this time.
'is this error normal
'The 0,0 should pick the latest version installed on that machine
Application.References.AddFromGuid Guid:=strGUID, Major:=0, Minor:=0
'If an error was encountered, inform the user
Select Case Err.Number
Case Is = 32813
'Reference already in use. No action necessary
Case Is = vbNullString
'Reference added without issue
Case Else
'An unknown error was encountered, so alert the user
MsgBox "A problem was encountered trying to" & vbNewLine _
& "add or remove a reference in this file" & vbNewLine & "Please check the " _
& "references in your VBA project!", vbCritical + vbOKOnly, "Error!"
End Select
On Error GoTo 0
End Sub
Thank you in advance