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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current record>Module>Dynamic e-mail

Status
Not open for further replies.

DajOne

Technical User
Jun 11, 2002
146
CA
I would appreciate help as I am to the end of my limited knowledge.

The goal is: upon the press of a button in a form, an e-mail is sent containing information on the current record.

I have the basic code to send the e-mail but i do not know:

a) What is the code to set the current record in the e-mail module below
b) What is the code format to insert the data from the current record in the form (ex: .Recipients.Add [????]..i.e. do I use the name or Control Source or the field name???



Sub SendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

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

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Yvan Dagenais")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Yvan Dagenais")
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "Credit request for:"
.Body = "[sales rep], your credit request for [client] in teh amount of [amount]is being reviewed by [credit officer]" & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub


 
You are making this way too hard on yourself. Use DoCmd.SendObject You can send a report or just a plain e-mail and you can use variables to fill any of the arguments. Give it a shot.

Hope this helps...T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top