Eljefegeneo
Still trying to learn
- Local time
- Yesterday, 20:41
- Joined
- Jan 10, 2011
- Messages
- 902
Using Access 2010 Late Binding
I am attempting to send an email with a word document in the body of the email. I have a form which I can fill out (or is filled out with the data of another form). The code below works fine in previous applications where I had
However, modifying the code to use the word document in the email, I get an error message on the line
The error message is:
Runtime Error 2147417851 (800 10 10 5)
Method of 'Body" of object '_MailItem' failed
Here is my code:
The correct document is open.
I am attempting to send an email with a word document in the body of the email. I have a form which I can fill out (or is filled out with the data of another form). The code below works fine in previous applications where I had
Code:
.Body = Cstr(Me.MessageBoy)
However, modifying the code to use the word document in the email, I get an error message on the line
Code:
.Body = woApp.ActiveDocument.Content
The error message is:
Runtime Error 2147417851 (800 10 10 5)
Method of 'Body" of object '_MailItem' failed
Here is my code:
Code:
Dim olApp As Object
Dim mItem As Object
Dim woApp As Object
Dim strDocument As String
Dim strTo, strCC2, strBCC2 As String
Dim strSubject, strMessageBody As String
strTo = Me.To
strCC2 = Nz(Me.CC, "")
strBCC2 = Nz(Me.BCC, "")
strSubject = Me.SubjectLine
strDocument = Me.AttachFile
Set olApp = CreateObject("Outlook.Application")
Set mItem = olApp.CreateItem(0)
Set woApp = CreateObject("Word.Application")
woApp.Visible = True
woApp.Documents.Open (strDocument) 'Correct document is open
With mItem
.To = CStr(strTo)
.CC = CStr(strCC2)
.BCC = CStr(strBCC2)
.Subject = CStr(strDocument)
.Body = woApp.ActiveDocument.Content "fails on this line
.Display ' To show the email message to the user
'.Send 'Sends without displaying
End With
End If
' Release all object variables
Set mItem = Nothing
Set olApp = Nothing
Set woApp = Nothing
The correct document is open.