Here is some sample code:
Create Reference from File
Sub AddWS()
'Create a reference to Windows Script Host, '
'where you will find FileSystemObject '
'Reference name: "IWshRuntimeLibrary" '
'Reference Name in references list: "Windows Script Host Object Model" '
ReferenceFromFile "C:WINDOWSSystem32wshom.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
From: http://wiki.lessthandot.com/index.php/Add,_Remove,_Check_References
You may also wish to read http://www.mvps.org/access/modules/mdl0022.htm
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…