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

Long mail message in Access 2007 using outlook

Status
Not open for further replies.

mutley1

MIS
Jul 24, 2003
909
I know i posted this in another thread, but I have found what seems to be a simple VBA to run the send of a message over 255 chars. Problem is, when I put the entire text of the email in, it doen not seem to like it and it auto add's speech marks etc. in the message body. Code is below.

Code:
Sub SendMessage(DisplayMsg As Boolean, 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("Nancy Davolio")
              objOutlookRecip.Type = olTo
 
              ' Add the CC recipient(s) to the message.
              Set objOutlookRecip = .Recipients.Add("Michael Suyama")
              objOutlookRecip.Type = olCC
 
             ' Add the BCC recipient(s) to the message.
              Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
              objOutlookRecip.Type = olBCC
 
             ' Set the Subject, Body, and Importance of the message.
             .Subject = "This is an Automation test with Microsoft Outlook"
             .Body = "This is the body of the message." &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
             Next
 
             ' Should we display the message before sending?
             If DisplayMsg Then
                 .Display
             Else
                 .Save
                 .Send
             End If
          End With
          Set objOutlook = Nothing
          End Sub

What I have is a screen with a mail button and when the user clicks it, Iwant Outlook to open a mail and include the following text:


Code:
Dear Client,

Please see attached a link to the payer list as requested. Tou may wish to bookmark this link for future usage.

[URL unfurl="true"]http://www.mylink/sfsddd/uyuy/list.asp[/URL]

Thank you again for choosing my company and we look forward to future dealings with youeself.

If you have any question, please contact us on the number below, selecting option 1 for enrollment or option 2 for support.

Thanks and have agreat day

EDI Support
My Company 
Phone # 800 111 2345

M.
So basically, click the button and the email is auto populated with this message.

Thanks in advance.

M
 
You could put the text of the Body into a common file.
Then, using fso, have some code like the following to get the file ( or you could just automate this without asking the question).

Code:
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
.....'
.....' other code you have in this area
''''''
Set fso = New FileSystemObject
' Now we need to put something in our letter...

BodyFile$ = InputBox$("Please enter the filename of the body of the message.", _
"We Need A Body!")

' If there’s nothing to say, call it a day.

If BodyFile$ = "" Then
MsgBox "No body, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain’t Got No-Body!"
Exit Function
End If

' Check to make sure the file exists...
If fso.FileExists(BodyFile$) = False Then
MsgBox "The body file isn’t where you say it is. " & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain’t Got No-Body!"
Exit Function
End If

' Since we got a file, we can open it up.
Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)

' and read it into a variable.
MyBodyText = MyBody.ReadAll

' and close the file.
MyBody.Close
......
......
'Then in your code use this
'to give it the body


' Set the Subject, Body, and Importance of the message.
             .Subject = "This is an Automation test with Microsoft Outlook"
             .Body = MyBodyText
             .Importance = olImportanceHigh  'High importance
.......
.......



Note: You should do a spell check on your message/body before sending.

Also, when resolving recipients you need some code along these lines to remove unresolved recipients
Code:
 ' Resolve each Recipient's name.
             For Each objOutlookRecip In .Recipients
                 objOutlookRecip.Resolve
                 'Remove unresolved recipients
                 If Not objOutlookRecip.Resolved Then
                     objOutlookRecip.Delete
                 End If
             Next

Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top