ACC97: How to Loop Through References to View Their Properties

ID: Q186305


The information in this article applies to:


SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

When you view the location of references with the Tools References dialog box, the trailing portion of the path name may be truncated because of the limitations of the dialog box. This article shows you how to use a Visual Basic for Applications procedure to loop through the References collection and retrieve the properties of each reference.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


MORE INFORMATION

To loop through the References collection and retrieve the properties of each reference, follow these steps:

  1. Create a module and type the following line in the Declarations section if it is not already there:


  2. 
    Option Explicit 
  3. Type the following procedure:


  4. 
        Sub ReferenceInfo()
          Dim strMessage As String
          Dim strTitle As String
          Dim bytButtons As Byte
          Dim refItem As Reference
    
          On Error Resume Next
    
          For Each refItem In References
             If IsError(refItem.Name) Then
                strTitle = "MISSING Reference"
                strMessage = "Missing Reference:" & vbCrLf & refItem.FullPath
                bytButtons = 16 'critical symbol
             Else
                strTitle = "Displaying References and Their Locations"
                strMessage = "Reference: " & refItem.Name & vbCrLf & _
                "Location: " & refItem.FullPath
                bytButtons = 64 'information symbol
            End If
    
          MsgBox prompt:=strMessage, Title:=strTitle, buttons:=bytButtons
    
          Next refItem
    
        End Sub 
  5. To test this function, type the following line in the Debug window, and then press ENTER:
    
    ReferenceInfo 
    Note that the message box opens for each reference.



REFERENCES

For more information about the References collection, search the Help Index for "References Collection," or ask the Microsoft Access 97 Office Assistant.

For more information about enumerating through the References collection by using the For Each...Next statement, search the Help Index for "For Next," select "For Each...Next statement", click Display and click "Using For Each... Next Statements" from the Topics Found dialog box.

For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

Q163435 VBA: Programming Resources for Visual Basic for Applications

Additional query words: reference


Keywords          : kbdta AccCon PgmHowto KbVBA 
Version           : WINDOWS:97
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 6, 1999