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

Sending string to Outlook but string is being word-wrapped? 1

Status
Not open for further replies.

jkirkland

Technical User
Apr 24, 2003
61
US
I posted this previously but the subject line may have been confusing. Anyway...

I'm sending email from VBA via Outlook using the following sub:

Sub EmailReport(ReportID As Long, ObjectType As String, ObjectName As String, OutputFormat As String, Subject As String, MsgText As String)
Dim db As Database
Dim rs As DAO.Recordset
Dim strBody As String

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM tblReportRecipients WHERE ObjectToSend = " & ReportID)

rs.MoveFirst
Do Until rs.EOF
DoCmd.SendObject acTable, ObjectName, OutputFormat, _
rs!EmailAddress, "", "", Subject, MsgText, False

'Log emails sent
Call LogEmailsSent(Now(), rs!EmailAddress, ObjectName)
rs.MoveNext
Loop
Set db = Nothing
Set rs = Nothing
End Sub

The sub works fine but the body of the message is a string representing the results of a recordset. In the Immediate window I get a nice string that where each value is separated from the previous value by a tab and each record is a single row in the string.

The problem is that when this string is emailed it gets word-wrapped in Outlook, even though the body area of the Outlook message has plenty of space. It seems to be wrapping it in about a 4 inch area.

Desired result:
101-0000-000.00-00 Supplies jsmith 9/9/06
101-0000-000.00-01 Machinery twatson 9/9/06

Problem I'm getting in Outlook:
101-0000-000.00-00 Supplies
jsmith 9/9/06
101-0000-000.00-01 Machinery
twatson 9/9/06

Thanks!
 
jkirkland,
Welcome to the wild and woderful world of [tt]SendObject()[/tt].

I did a quick test in Access 2k SR-1 sending a 255 character string as the message text using [tt]SendObject()[/tt] and it wrapped the text every 30 chracters.

When I check your string lengths it appears they are being wrapped every 30 characters, imagine that.

Must be hard coded into the [tt]SendObject()[/tt] function to wrap long strings. Only work around I can see is to create your own emails using OLE automation. It's a little more work but you receive a lot more control over the final format of the email.

Try searching for '[tt]Outlook.Application[/tt]' or '[tt]CreateItem[/tt]' for examples on how to do this.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
I hadn't even thought to try it with OLE. I'll give it a try.

Thanks for the help!
 
JKirkland-

Here is an example for Outlook.Application method:

Code:
Private Sub Submit_Click()


Dim appOutlook As Outlook.Application
Dim ItmNewEmail As Outlook.MailItem



DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 'save record before proceeding

Set appOutlook = New Outlook.Application
Set ItmNewEmail = appOutlook.CreateItem(olMailItem)


With ItmNewEmail
     .To = "add1@domain.com; add2@domain.com"
     .CC = Forms("FormName").Controls("RequestorEmail").Value
     .Subject = "Subject"
     .Body = "A new email has been sent by" & Forms("FormName").Controls("ControlName").Value & " for Job Number " & Forms("FormName").Controls("ControlName").Value & Chr(13) & "sample text" & Forms("FormName").Controls("ControlName").Value & Chr(13) & Chr(13)      

     .Send                    ' send files and notification
End With

End Sub

You should be able to modify this to do what you want.

Hope this helps,

Alex


It's a magical time of year in Philadelphia. Eagles training camp marks the end of another brutal season of complaining about the Phillies.
 
CautionMP, Thanks for the help. Using OLE fixed the problem. I hadn't thought the two would give different results.

Alex, thanks for the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top