Not sure where I dredged this from. Sorry for lack of attribution. You can add a sub to outlook and then debug in outlook when/if it fails.
It has been a while since I used this. It may be the case that Office 2010 chokes on it.
Code:
'
' outlook code
'
Private Sub Application_Startup()
Dim x As Integer
x = 1
Debug.Print "Ran this."
End Sub
Public Sub SendMessage(filename As String, _
recip As String, _
text As String, _
subj As String)
' Send a message to your new contact.
Dim olMail As Outlook.MailItem
Set olMail = Application.CreateItem(olMailItem)
' Fill out & send message...
olMail.To = recip
olMail.Subject = subj
olMail.Body = text
If filename <> "" Then
olMail.Attachments.Add filename
End If
olMail.Send
End Sub
Then add an outlook mail class in access
Code:
'
' access class OutlookSendMail
'
Option Compare Database
Option Explicit
'
' Note is object is dependend on the routine in outlook
' for sending email.
'
' also note that for some reason code needs to be executed in
' outlook_startup to permit proper sendmessage calls
'
Dim app As Object ' early binding Outlook.Application
Function offlineCheck() As Boolean
offlineCheck = app.Session.offline
End Function
Sub outlookSendMessage(sendto As String, _
subj As String, _
attch As String, _
Msg As String)
Dim X As String
X = app.SendMessage(attch, sendto, Msg, subj)
End Sub
Private Sub Class_Initialize()
Set app = CreateObject("Outlook.Application")
app.Session.Logon
End Sub
Private Sub Class_Terminate()
app.Session.Logoff
Set app = Nothing
End Sub
And the code to use the class
Code:
Public Sub setupPostOffice()
Dim outlk As Object ' early binding OutlookSendMail
Set outlk = New OutlookSendMail
checkAgain:
If outlk.offlineCheck = False Then
MsgBox "Set Outlook Session to be Offline via:" & _
chr(13) & chr(13) & " File->Work_Offline" & _
chr(13) & chr(13) & "inside Outlook."
GoTo checkAgain
End If
End Sub
Public Sub TakedownPostOffice()
Dim outlk As Object ' early binding OutlookSendMail
MsgBox "Reminder: To send the email you" & chr(13) & _
"need to deselect Work offline via menu:" & chr(13) & chr(13) & _
" File->Work Offiline" & chr(13) & chr(13) & _
"in Outlook or select Send All from the Send/Recieve dropdown menu."
Set outlk = Nothing
End Sub
...
setupPostOffice
...
' loop for multiple message
outlk.OutlookSendMessage_
filename, _
towho, _
message_final, _
Subject
...
TakedownPostOffice
...