I call this function before I run the code that uses outlook to email - however it won't add the library. Outside of the function this code works fine, in a public function in a module it won't work...
Code:
'adds the outlook library
Public Function addOutlookLibrary() As Boolean
Dim ref As Object
Dim OutlookPath As String
dim refexists as boolean
OutlookPath = "C:\Program Files (x86)\Microsoft Office\Office14\MSOUTL.OLB"
If Len(Dir(OutlookPath)) = 0 Then
MsgBox "You are missing the required library, you can't use this form to send emails"
addOutlookLibrary = False
Exit Function
Else
refexists = False
For Each ref In References
Debug.Print ref.Name
If ref.Name = "Outlook" Then
refexists = True
End If
Next
If refexists = False Then
Access.References.AddFromFile (OutlookPath)
End If
addOutlookLibrary = True
End If
End Function