Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference Detection - Can It Be Done? 1

Status
Not open for further replies.

GGleason

Technical User
Mar 22, 2001
321
US

Within a module, I want to be able to detect if the Microsoft Excel 8.0 Object Library (EXCEL8.OLB) is checked as a reference. Then, if it is not checked, to be able activate it within the module.

Is this even possible?

tia,
GGleason
 
This is out of Access Help. Although, I haven't done it, it sure looks like this will work.
Reference Object, 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

 
Thanks. I should have looked in the help, but I thought this was so esoteric that I didn’t even bother.

The good news is that the code worked but I modified it to suit my needs.

Here is the modified function:

Function ReferenceFromFile(strFileName As String, strRefName As String) As Boolean
Dim ref As Reference, i As Integer

On Error GoTo Error_ReferenceFromFile

For i = 1 To References.Count
If References.Item(i).Name = strRefName Then
ReferenceFromFile = True
Exit Function
End If
Next i

Set ref = References.AddFromFile(strFileName)
ReferenceFromFile = True

Exit_ReferenceFromFile:
Exit Function

Error_ReferenceFromFile:
MsgBox Err & ": " & Err.Description
ReferenceFromFile = False
Resume Exit_ReferenceFromFile
End Function

Here is the revised code that calls the function:

If ReferenceFromFile("C:\Program Files\Microsoft Office\Office\EXCEL8.OLB", "Excel") = True Then
' MsgBox "Reference set successfully."
Else
MsgBox "Excel reference not set successfully!", vbExclamation
End If

This helps a lot!

Many thanks,
GGleason

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top