Reference Object

Description

The Reference object refers to a reference set to another application's or project's type library.

Remarks

When you create a Reference object, you set a reference dynamically from Visual Basic.

The Reference object is a member of the References collection. To refer to a particular Reference object in the References collection, use any of the following syntax forms.

Syntax

Description

References!referencename

The referencename argument is the name of the Reference object.

References("referencename")

The referencename argument is the name of the Reference object.

References(index)

The index argument is the object's numerical position within the collection.


The following example refers to the Reference object that represents the reference to the Microsoft Access type library:

Dim ref As Reference
Set ref = References!Access
Properties

BuiltIn property, Collection property, FullPath property, GUID property, IsBroken property, Kind property, Major property, Minor property, Name property.

See Also   References collection.

Example

The following example creates a reference to a specified type library:

Function ReferenceFromFile(strFileName As String) As Boolean
    Dim ref As Reference

    On Error GoTo Error_ReferenceFromFile
    Set ref = References.AddFromFile(strFileName)
    ReferenceFromFile = True

Exit_ReferenceFromFile:
    Exit Function

Error_ReferenceFromFile:
    MsgBox Err & ": " & Err.Description
    ReferenceFromFile = False
    Resume Exit_ReferenceFromFile
End Function
You could call this function by using a procedure such as the following, which creates a reference to the calendar control:

Sub CreateCalendarReference()
    If ReferenceFromFile("C:\Windows\System\Mscal.ocx") = True Then
        MsgBox "Reference set successfully."
    Else
        MsgBox "Reference not set successfully."
    End If
End Sub