Question : Late binding Outlook - type mismatch on object assignment

Hello -
I am working with an application that has been written in Access 2007. This application sends Outlook messages, and originally had Outlook 12 included as a reference. Although most users have Outlook 2007, some are still on Outlook 2003. When implemented, the application will be run as a run-time application ( i.e. "accdr"). When I tried to run the accdr on a machine with only Outlook 2003 running, the application abended. I tried to swap in the proper reference when the application starts, but I still got the same error (in run-time, it just ends with a cryptic message about a 'critical error' - and yes I have error messaging set up throughout the application). I am trying to get around this by using late-binding for the Outlook objects
I removed the Outlook reference, and revised the code as seen below. I am getting this error on an XP machine with Office 2007 installed, and another with XP and Office 2003, Access 2007 Runtime installed. On both machines, when I am running the app, I have Outlook started up.
I am getting an error on line 40. What can I do to get this to work?
BTW, running this as an mdb is not an option.
Thanks,
Todd
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Public Function SetupEmail(strSendTo As String, strSubject As String, strMsg As String) As Boolean
      Dim olkApp As Object
      Dim olkMsg As Object
      Const strProcedure As String = "SetupEmail"
10    On Error GoTo ErrorHandler
 
20    Set olkApp = CreateObject("Outlook.Application")
30    With olkApp
40       Set olkMsg = .CreateItem("Outlook.MailItem")  '<== 'Object mis-match here
50       With olkMsg
60          .Recipients.Add strSendTo
100         .Subject = strSubject
110         .Body = strMsg
120         .Display
130      End With
140   End With
         
150   SetupEmail = True
ExitFunction:
160   On Error Resume Next
170   Set olkMsg = Nothing
180   Set olkApp = Nothing
190   On Error GoTo 0
200   Exit Function
 
ErrorHandler:
210   HandleError strModule, strProcedure, Err.Description, Err.Number, Erl
220   Resume ExitFunction
End Function

Answer : Late binding Outlook - type mismatch on object assignment

With early or late binding - that should be just:
Set olkMsg = .CreateItem(0)

Or with early binding and you want to use the constant:
Set olkMsg = .CreateItem(olMailItem)  

You're currently passing a string argument to an expected integer type parameter (of olItemType).
Hence the error.

Cheers.
Random Solutions  
 
programming4us programming4us