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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to use multiple outlook versions to send mail

Status
Not open for further replies.

amber17

Programmer
Apr 2, 2007
6
GB
Hi,

I apologize now if I am asking a silly question, but to say I'm new to access would be an understatement. I have a database that auto generates emails. The database sits on a server and is accessed by users using Microsoft outlook 10. We recently had a machine upgraded and the IT department have installed outlook 2003, which needs Microsoft Outlook Library 11.0.

At the moment I cant seem to find a way to reference both Microsoft Object Libraries. If I select 10 the new PC can't log in and if I select 11 all other users are logged out. I have been desperately trying to find a way of referencing both libraries but to no avail. Is there anyone that could suggest a method I can use to use both versions of outlook in the database. I have provided the code for the send mail function below:

Public Function SendMail(strFrom, strTo As String, strCC As String, strBCC As String, strSubject As String, strBody As String) As Boolean
On Error GoTo errSendMail

Dim objOL As New Outlook.Application
Dim objMail As MailItem

Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)

With objMail
.BodyFormat = olFormatHTML
.HTMLBody = strBody
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.SentOnBehalfOfName = strFrom
.Display
End With

Set objMail = Nothing
Set objOL = Nothing

'return true on success
SendMail = True
Exit Function

errSendMail:
SendMail = False
MsgBox (Err.Description)

End Function
 
Late binding may help

Dim objOL

Set objOL = CreateObject("Outlook.Application")

Ignorance of certain subjects is a great part of wisdom
 

And just to mention that

Dim objOL As New Outlook.Application
Set objOL = New Outlook.Application

creats objOL twice!

It is very recomended to avoid statements like this
Dim xxx As New ....


As for Late binding that AlexCuse suggests, you 'll have to replace olMailItem with 0 and olFormatHTML with 2. Since you shall not reference the Microsoft Outlook Library, these constants wont be defined and shall produce errors.
 
Hi Alex and Jerry,

I tried using the suggested late binding code and it has worked a treat, with some other minor modifications. Thanks for your help, greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top