The code provided is valid but you must set a reference to the MS Outlook
Object library:
In any module click on > References > Microsoft Outlook (version no.) Object
Library > OK.
Good luck.
BW
Stapes said:
Hi
I'm fairly certain that you can't add the recipients address using the
SendMail method.
I suggest you use automation to send the document using MS Outlook (if MSO
is available).
Go to:
http://msdn2.microsoft.com/en-us/library/aa159619(office.11).aspx
for the coding.
Cheers.
BW
:
Hi
Here is my code:
If Not IsNull(([Forms]![Process Bookings]![Booking Form].Form.Email))
Then
Options.SendMailAttach = True
objWord.ActiveDocument.SendMail
How do I specify the recipients address?
Stapes- Hide quoted text -
- Show quoted text -
That didn't work. The code provided is invalid. The first line causes
the error - User type not defined (Dim objOutlook As
Outlook.Application).
This was a line of code I found elsewhere:-
objWord.ActiveDocument.SendMail Recipients:="(e-mail address removed)"
That doesn't work either. I get Compile error: Wrong number of
arguments or invalid property assignment.
Does anybody out there know how to do this?
Stapes- Hide quoted text -
- Show quoted text -
Ok. Got that working. However, I am creating my attachment in the
code, like this:-
Dim objWord As Word.Application
' in order for this to work - go to Tools / References and tick
Microsoft Word 11.0 Object Library
Set objWord = CreateObject("Word.Application")
With objWord
' Make the application visible.
.Visible = True
' Open the document.
.Documents.Open ("C:\Documents and Settings\stephen\Desktop
\Glynn Barton\Confirmation.doc")
' Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("BkmrkRecipientsName").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[ContactFirstName]) & " " & ([Forms]![Process
Bookings]![Booking Form].Form.[ContactLastName])))
.ActiveDocument.Bookmarks("BkmrkRecipientsName2").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[ContactFirstName]) & " " & ([Forms]![Process
Bookings]![Booking Form].Form.[ContactLastName])))
.ActiveDocument.Bookmarks("BkmrkBillingAddress").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[BillingAddress])))
.ActiveDocument.Bookmarks("BkmrkCity").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[City])))
.ActiveDocument.Bookmarks("BkmrkStateOrProvince").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[StateOrProvince])))
.ActiveDocument.Bookmarks("BkmrkPostalCode").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[PostalCode])))
.ActiveDocument.Bookmarks("BkmrkCountryRegion").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[Country/Region])))
.ActiveDocument.Bookmarks("BkmrkTodaysDate").Select
.Selection.Text = Date
.ActiveDocument.Bookmarks("BkmrkNoOfWeeks").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[NoOfWeeks])))
.ActiveDocument.Bookmarks("BkmrkArrivalDate").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.[DateOfArrival])))
.ActiveDocument.Bookmarks("BkmrkResourceName").Select
.Selection.Text = (CStr(([Forms]![Process Bookings]!
[Booking Form].Form.Combo89.Column(1))))
End With
' Print the document in the foreground so Microsoft Word 97
' will not close until the document finishes printing.
If Not IsNull(([Forms]![Process Bookings]![Booking
Form].Form.Email)) And InStr(([Forms]![Process Bookings]![Booking
Form].Form.Email), "@") Then
Options.SendMailAttach = True
objWord.ActiveDocument.SendMail Recipients:=([Forms]!
[Process Bookings]![Booking Form].Form.Email)
The example code uses:
Dim objOutlookAttach As Outlook.Attachment
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
I guess it is expecting a file name. Is there any way I can just
attach my Word document?
Stapes