Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create an Email from an Access Form 3

Status
Not open for further replies.

scantron

Programmer
Jul 4, 2002
27
CA
Hi there,

I was wondering if there's a way that I can create a dynamic email based on fillable fields on an MS Access form?

I'm using 2003, and the only email functionality I'm able to find is the wizard type where your only options are who you want to send to (static) and the Subject line (static).

I'd like to have Outlook open to a new message, and have the 'To' field, 'Subject' field, and Body of the email, all populated by user entered data from the Access form.

so if a user types in john@hotmail.com, and you click the 'Email' hyperlink, john's email address would populate the new email message. I would also like for there to be dynamic content in the body of the email aswell, based on other input fields on an Access form.

Thanks for any ideas or help you may have.

Chris

have an access form hyperlink, open a new email in Outlook, where the 'To' field, Subject line, and Body are all created
 
This is what I have used:

Private Sub SendEMail()
''' Send E-mail report file
Dim oOutlookApp As Outlook.Application
Dim oMailItem As Outlook.MailItem
Dim oAttach As Outlook.Attachments
Dim sAttachFile As String
Dim sRecipents '''array
Dim k As Integer, r As Integer

On Error GoTo Err_cmdEmailNotice_Click

sRecipents = Array(Me.txtEMailAddress)
sAttachFile = "c:\MyAttachmentFile.txt"

If vbNo = MsgBox("Are you sure, MS Outlook must be open before continuing?", vbQuestion + vbYesNo, _
"ccMail Send Confirmation") Then GoTo Exit_cmdEmailNotice_Click

DoCmd.Hourglass True

Set oOutlookApp = New Outlook.Application
Set oMailItem = oOutlookApp.CreateItem(olMailItem)
Set oAttach = oMailItem.Attachments

r = UBound(sRecipents)
For k = 1 To r
Call oMailItem.Recipients.Add(sRecipents(k))
Next k

'''Message Body
oMailItem.Subject = Me.txtSubject
oMailItem.Body = Me.txtBody

'''Add file as an attachment
oAttach.Add sAttachFile

oMailItem.Send

MsgBox "Mail notification completed.", vbInformation + vbOKOnly

Exit_cmdEmailNotice_Click:
Set oMailItem = Nothing
Set oOutlookApp = Nothing

DoCmd.Hourglass False

Exit Sub

Err_cmdEmailNotice_Click:
MsgBox Err.Description
Resume Exit_cmdEmailNotice_Click

End Sub
 
Hi FXP, Thanks for the tip.

So I altered the code to fits my needs. ex. got rid of the array as I'm only dealing with one contact at a time.

When I try to execute the code, I get a comile error. User-defined type not defined, on this line:

Dim oOutlookApp As Outlook.Application

Must I first define this type?

Thank you

Chris
 
scantron,
do you have outlook referenced? in the vba editor select tools the references. i believe that you need ms outlook 9.0 object library selected.

regards,

longhair
 
You guys rule! Anyone know how I can insert line breaks into the Body of the email?

Thanks

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top