Credit goes to
Richard Rensel (nick QDS) of UtterAccess.com for this answer. I was posting in a hurry originally to get a problem done, so I gave the answer without stopping to think about credit. I just thought he should get an answer too because he made me think about needing it. Thanks Richard! and thank you R. Hicks for pointing this out! I assure you I always try to give credit where it is due.
You can find this in the Help Files. 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