How can i insert a record from access into outlook using automati.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i am using XP Professionel. In access i have used automation to open an
outlook page (e-mail) In the body of the message i would like to insert a
access record is this possible
 
Instead of using automation to open outlook, use the following command
DoCmd.SendObject acSendNoObject, , acFormatTXT, _
"To", "CC", "BCC", "Subject", "Message", True
You can change the variables in the quotes to match anything you wish,

Dale
 
If you wish to add the contents of a record, I suggest you have a form open
that has the record you want to use on it, and a command button linked to the
code listed a little later.

For this demo assume the form has four fields called: Fname, LName, DOB, Sex

The contents of your record for the above fields is: John, Smith, 15th June
1967, Male

in the 'on click' event for your button put the following code.

'Takes the contents of the fields and put them into variables.
Firstname = Form.Fname
Lastname = Form.Lname
DateBirth = Form.DOB
MF = Form.Sex

'Build the body of the E-mail
Bodytext = "First Name: " & Firstname +CHR(13)
Bodytext = Bodytext & "Last Name: " & Lastname +CHR(13)
Bodytext = Bodytext & "Date Of Birth: " & DateBirth +CHR(13)
Bodytext = Bodytext & "Sex: " & MF

Dim objOutlook As Object
Dim objmailItem As Object

'Create the Outlook object
Set objOutlook = CreateObject("Outlook.Application")

'Access a new mail item
Set objmailItem = objOutlook.CreateItem(olmailItem)

'Do things with the E-mail
With objmailItem
..Body = bodytext
..display 'Use .Send if you want the message sent instead of display
End With

Set objmailItem = Nothing
Set objOutlook = Nothing

'End Of Code.....................

What this does is take the contents of the fields, and add them to an Ascii
string called Bodytext.
The code then creates an Outlook object, and using the .body property
inserts the variable Bodytext into the body of the e-mail, creating and Email
looking something like this:

First Name: John
Last Name: Smith
Date Of Birth: 15th June 1967
Sex: Male

All you would need to do is select recipients for the Email, and a subject
line.
These can also be added programatically is you wish using the .to property
and .subject property eg.
..to = "(e-mail address removed)"
..subject = "This is an E-mail"

There are also properties such as .cc, .bcc, .importance,
..readrecieptrequested. which can all be set programatically if required.

Hope this is all clear enough and helps, if not please post again or contact
me.

Neil
www.nwarwick.co.uk
 
This is a VERY HELPFUL post. Thank you.

Now I have some more questions.
I also have on my form:

TO:
CC:
SUBJECT:

What is the code to add that so that it can populate automatically from my
form?
 
The commands you need are .to .cc and .subject respectively:

e.g. if your E-mail recipient address is in a variable called EmailRecipient
then to add them to the 'To:' box use:

..to = EmailRecipient

The same then applies to .cc and .subject

Note, if you're going to add multiple email adresses then you will also need
to add a semi-colon like this

..to = EmailRecipient & ";" & EmailRecipient2 & ";" & EmailRecipient3

Hope this helps (If not please post back)

Neil
www.nwarwick.co.uk
 
This worked perfectly, thanks for being patient with me.

Now I want to get fancy.

I want three fields to repeat for each record that the user makes.
(Probably I'm doing it backwards, but I made three fields:)

txtbody1
txtbody2
txtbody3

In all three fields I put the message, something like:
txtbody1 (this will always be the same for each email)
Welcome to my company. We want to acknowledge that you have bought the
following products:

txtproducts are listed here

txtbody2 (this will always be the same for each email)
We will be contacting you shortly to confirm this order.
etc.

So I made txtbody1 and txtbody2 NOT visible. When the user goes to click
another record, I want txtbody1 and txtbody2 to always be there with the
pre-determined text (that they cannot edit on the form).

Can you tell me how to do this?
 
Sounds like you just need to create a string-type variable with the text
and then concatanate(sp) them for the message body.

strMessageHeader = "Thank you for shopping at MegaMart."
strMessageFooter = "Please pay your bill promptly to ensure that your
first born is not taken as payment."

Then
..Body* = strMessageHeader & "Here are your products" & strMessageFooter
*or correct property to set the message text - I'm always looking it up

which results in ...

Thank you for shopping at MegaMart.Here are your products.Please pay...
 
Back
Top