Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Add, Remove, Check References

From Wiki

Jump to: navigation, search

You must use the full path to create a reference from a file.

Example: Create Reference from File

  Sub AddWS()
  'Create a reference to Windows Script Host, 
  'where you will find FileSystemObject
  'Reference name: Case "IWshRuntimeLibrary"
  'Reference Name in references list: "Windows Script Host Object Model"
  ReferenceFromFile "C:\WINDOWS\System32\wshom.ocx"
  End Sub
   
  Function ReferenceFromFile(strFileName As String) As Boolean
  Dim ref As Reference
      
         On Error GoTo Error_ReferenceFromFile
         References.AddFromFile (strFileName)
         ReferenceFromFile = True
      
  Exit_ReferenceFromFile:
         Exit Function
   
   Error_ReferenceFromFile:
         ReferenceFromFile = False
         Resume Exit_ReferenceFromFile
   End Function 
  

Delete Reference

  Sub DeleteRef(RefName)
  Dim ref As Reference
   
      'You need a reference to remove
      Set ref = References(RefName)
      References.Remove ref
   
  End Sub 
  

You can use the references collection to find if a reference exists.

Reference Exists

  Function RefExists(RefName)
  Dim ref As Object
      
     RefExists = False
      
     For Each ref In References
         If ref.Name = RefName Then
             RefExists = True
         End If
     Next
      
  End Function
   

This is for administration purposes, it will merely list references to the immediate window.

List All References

  Sub ListRefs()
  Dim ref As Reference
   
  For Each ref In References
      Debug.Print RefFullName(ref.Name)
      Debug.Print "Built In: " & ref.BuiltIn
      Debug.Print "Full Path: " & ref.FullPath
      Debug.Print "GUID: " & ref.Guid
      Debug.Print "Is Broken: " & ref.IsBroken
      Debug.Print "Kind: " & ref.Kind
      Debug.Print "Major (version number): " & ref.Major
      Debug.Print "Minor (version number): " & ref.Minor
      Debug.Print "Name: " & ref.Name
      Debug.Print '=================================
  Next
   
  End Sub
   
  Function RefFullName(ReferenceName)
  'A mere handful of common names
  'These names are relevant to Access 2000 
  'and are for purposes of illustrating the name
  'as used in Reference Name and the library
  'name as it appears in Tools->References
  Select Case ReferenceName
      Case "Access"
          RefFullName = "Microsoft Access 9.0 Object Library"
      Case "ADODB"
          RefFullName = "Microsoft ActiveX Data Objects 2.1 Library"
      Case "CDO"
          RefFullName = "Microsoft CDO for Windows 2000 Library"
      Case "DAO "
          RefFullName = "Microsoft DAO 3.6 Object Library"
      Case "Excel"
          RefFullName = "Microsoft Excel 9.0 Object Library"
      Case "IWshRuntimeLibrary"
          RefFullName = "Windows Script Host Object Model"
      Case "Office"
          RefFullName = "Microsoft Office 9.0 Object Library"
      Case "Outlook"
          RefFullName = "Microsoft Outlook 9.0 Object Library"
      Case "stdole"
          RefFullName = "OLE Automation"
      Case "VBA"
          RefFullName = "Visual Basic For Applications"
      Case "VBIDE"
          RefFullName = "Microsoft Visual Basic for Applications Extensibility 5.3"
      Case "Word"
          RefFullName = "Microsoft Word 9.0 Object Library"
      Case Else
          RefFullName = "Not available in this very limited list."
  End Select
   
  End Function

Further Information References Collection: http://msdn2.microsoft.com/en-us/library/aa210671.aspx

Collections: http://office.microsoft.com/en-gb/access/HP011359551033.aspx?pid=CH011413201033

Modules: References Wizard: http://www.mvps.org/access/modules/mdl0022.htm(office.10).aspx

About how Access searches for reference libraries: http://office.microsoft.com/en-gb/access/HP030797131033.aspx?pid=CH062526221033

Fix a reference to a library: http://office.microsoft.com/en-gb/access/HP052788661033.aspx?pid=CH063648701033

273 Rating: 1.0/5 (2 votes cast)