E
Ernst Guckel
Hello,
We are having a bit of dificulty with the following code. It works when
Ourlook is open but not when closed. We recieve an 'Application defined'
error on the line MyMail.Send... References to Outlook are checked. Any help
would be great.
Public Sub SendEMail(strMailTo As String, strFile As String, _
strSubject As String, Optional strFileDesc As String, Optional strBody
As String, _
Optional strBCC As String)
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim strTag As String
Dim strName As String
Dim strEmail As String
strTag = DLookup("Tag", TABLE_ORGDATA)
strName = DLookup("OrganizationName", TABLE_ORGDATA)
strEmail = DLookup("Email", TABLE_ORGDATA)
' Now, we open Outlook for our own device..
Set MyOutlook = New Outlook.Application
'This creates the e-mail
Set MyMail = MyOutlook.CreateItem(olMailItem)
' This addresses it
MyMail.To = strTag
'This addresses BCC
MyMail.BCC = strBCC
'MsgBox strBCC
'This gives it a subject
MyMail.Subject = strSubject
'This gives it the body
MyMail.Body = strBody
'This attaches a file
If strFile <> "" Then
MyMail.Attachments.Add strFile, olByValue, 1, strFileDesc
End If
'This sends it!
MyMail.Send
'Cleanup after ourselves
Set MyMail = Nothing
End Sub
We are having a bit of dificulty with the following code. It works when
Ourlook is open but not when closed. We recieve an 'Application defined'
error on the line MyMail.Send... References to Outlook are checked. Any help
would be great.
Public Sub SendEMail(strMailTo As String, strFile As String, _
strSubject As String, Optional strFileDesc As String, Optional strBody
As String, _
Optional strBCC As String)
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim strTag As String
Dim strName As String
Dim strEmail As String
strTag = DLookup("Tag", TABLE_ORGDATA)
strName = DLookup("OrganizationName", TABLE_ORGDATA)
strEmail = DLookup("Email", TABLE_ORGDATA)
' Now, we open Outlook for our own device..
Set MyOutlook = New Outlook.Application
'This creates the e-mail
Set MyMail = MyOutlook.CreateItem(olMailItem)
' This addresses it
MyMail.To = strTag
'This addresses BCC
MyMail.BCC = strBCC
'MsgBox strBCC
'This gives it a subject
MyMail.Subject = strSubject
'This gives it the body
MyMail.Body = strBody
'This attaches a file
If strFile <> "" Then
MyMail.Attachments.Add strFile, olByValue, 1, strFileDesc
End If
'This sends it!
MyMail.Send
'Cleanup after ourselves
Set MyMail = Nothing
End Sub