Option Compare Database Option Explicit 'Comments : Adds or removes a reference to any library, depending on current state of the reference 'Parameters: strErrHndlr - name of the library file ' strPath - full path to installed library ' strRefName - internal name of library ' bMessages (Optional) - show success/failure messages; default=True 'Sets : If the library is currently referenced, the reference is removed ' If the library is not currently referenced, attempt to add a reference to it 'Returns : Nothing - written as a function so it can be used in a macro 'Created by: Seth D. Galitzer 'Created : 2/17/1999 2:57:24 PM Public Function basToggleRef(strLibrary As String, strPath As String, strRefName As String, Optional bMessages = True) On Error GoTo Err_basToggleRef Const conErrRef = 9999 'Local error definition Dim ref As Reference Dim bFound As Boolean bFound = False 'Initialize flag 'Check if the library is currently referenced, and remove the reference if appropriate For Each ref In References With ref If .NAME = strRefName Then If basRemoveReference(ref) Then If bMessages Then MsgBox "Reference to " & strRefName & " successfully removed!", vbInformation, "Reference Removed" End If Else Err.Raise conErrRef End If bFound = True End If End With Next 'The library is not currently referenced, attempt to reference it If Not bFound Then If basAddReferenceFromFile(strPath & "\" & strLibrary) Then If bMessages Then MsgBox "Reference to " & strRefName & " successfully added!", vbInformation, "Reference Added" End If Else Err.Raise conErrRef End If End If Exit_basToggleRef: Exit Function Err_basToggleRef: Select Case Err Case 0 'insert Errors you wish to ignore here Resume Next Case conErrRef 'Either adding or removing the reference failed MsgBox "Error setting reference to " & strRefName, vbExclamation, "Reference Error" Resume Exit_basToggleRef Case Else 'All other errors will trap Beep MsgBox Err & ": " & Err.Description, , "Error in function modReferences_Reg.basToggleRef" Resume Exit_basToggleRef End Select Resume 0 'FOR TROUBLESHOOTING End Function 'Comments : Adapted from Access97 Help 'Parameters: strFileName - the name of the library file to be referenced 'Sets : Adds a reference based on the filename passed in 'Returns : Success=True; Failure=False 'Created by: Seth D. Galitzer 'Created : 2/17/1999 11:53:29 AM Function basAddReferenceFromFile(strFileName As String) As Boolean On Error GoTo Err_basAddReferenceFromFile Const conErrBadDll = 48 Const conErrAlrdyRef = 32813 Dim ref As Reference Dim bRet As Boolean bRet = False 'init flag, may be unneccessary Set ref = References.AddFromFile(strFileName) bRet = True Exit_basAddReferenceFromFile: basAddReferenceFromFile = bRet Exit Function Err_basAddReferenceFromFile: Select Case Err Case 0 'insert Errors you wish to ignore here Resume Next Case conErrBadDll MsgBox "Cannot add a reference to this library.@The file name is invalid.@", vbCritical, "Error Adding Reference" Resume Exit_basAddReferenceFromFile Case conErrAlrdyRef MsgBox "This library is already referenced.@Make sure you have spelled the Reference Name correctly.@", vbCritical, "Error Adding Reference" Resume Exit_basAddReferenceFromFile Case Else 'All other errors will trap Beep MsgBox Err & ": " & Err.Description, , "Error in function modReferences.basAddReferenceFromFile" Resume Exit_basAddReferenceFromFile End Select Resume 0 'FOR TROUBLESHOOTING End Function 'Comments : Adapted from Access97 Help 'Parameters: ref - the member of Application.References to be removed 'Sets : Removes a reference based on that which is passed in 'Returns : Success=True; Failure=False 'Created by: Seth D. Galitzer 'Created : 2/17/1999 2:50:16 PM Function basRemoveReference(ref As Reference) As Boolean On Error GoTo Err_basRemoveReference Dim bRet As Boolean bRet = False 'init flag, may be unneccessary References.Remove ref bRet = True Exit_basRemoveReference: basRemoveReference = bRet Exit Function Err_basRemoveReference: Select Case Err Case 0 'insert Errors you wish to ignore here Resume Next Case Else 'All other errors will trap Beep MsgBox Err & ": " & Err.Description, , "Error in function modReferences.basRemoveReference" Resume Exit_basRemoveReference End Select Resume 0 'FOR TROUBLESHOOTING End Function