?
Solved

Visual Basic 6 and Microsoft Outlook

Posted on 2004-04-20
9
Medium Priority
?
357 Views
Last Modified: 2010-08-05
I am in Visual BAsic 6 I an am calling up a new email and I want the
body of the email to print what is in my text boxes.

The Code I have
**********************************************************
Sub Create_an_email()

my_text1 = text1.text (that has in it Hello)
my_text2 = text2.text (that has in it Bonjour)
my_text3 = text3.text (that has in it Hola)
my_text4 = text4.text (that has in it How Dee)

Set myOLApp = CreateObject("Outlook.Application")
Set myItem = myOLApp.CreateItem(olMailItem)
myItem.Display

With myItem
        .Subject = "Test"
        .Body = my_text1 & my_text2 & my_text3 & my_text4
    End With
    myItem.Display

End Sub

**********************************************************

But what happens is the email.body comes out like this:

HelloBonjourHolaHow dee

How can I get it to come out like this:

Hello

Bonjour

Hola

How dee

On New lines, with enters.

Also I want the email to be a plain text email.

Thanks,

Jason.
0
Comment
Question by:JasonAsh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Assisted Solution

by:taherzm
taherzm earned 248 total points
ID: 10869515
try this

**********************************************************
Sub Create_an_email()

my_text1 = text1.text (that has in it Hello)
my_text2 = text2.text (that has in it Bonjour)
my_text3 = text3.text (that has in it Hola)
my_text4 = text4.text (that has in it How Dee)

Set myOLApp = CreateObject("Outlook.Application")
Set myItem = myOLApp.CreateItem(olMailItem)
myItem.Display

With myItem
        .Subject = "Test"
        .Body = my_text1 & vbNewLine & my_text3 & vbNewLine & my_text4
    End With
    myItem.Display

End Sub

**********************************************************

0
 
LVL 2

Accepted Solution

by:
www_SMR_co_uk_was_too_offensive earned 252 total points
ID: 10869538
you need to add carriage returns (Enter keystrokes). When I press enter like
this a special pair of characters is written with the ASCII codes 13 and 10 (in that order). They correspond to Carriage Return and Line Feed (these two things hark back to the days of electric typewriters. CR moves the cursor to the start of the line on the left and LF moves it down one line).

VB has a special bunch of constants for inserting these special characters:
vbCr - Carriage Return
vbLf - Line Feed
vbCrLf - carriage return and then linefeed (two chars)
vbTab - Tab character
etc

you want a pair of newlines (a blank line in between) so you should do this:


[snip]
With myItem
       .Subject = "Test"
       .Body = my_text1 & vbCrLf & vbCrLf & my_text2 & vbCrLf & vbCrLf & my_text3 & vbCrLf & vbCrLf & my_text4
   End With
[/snip]


hope that helps

=me=
0
 
LVL 2
ID: 10869726
hehe dammit you beat me to it taherzm! However I got both the newlines in so naa! I can't find anything on making the email plain text not html though. msdn isn't very helpful. any thoughts?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:JasonAsh
ID: 10869744
Thanks both sets of code worked.

Cheers,

Jason.
0
 
LVL 4

Expert Comment

by:palamangelus
ID: 10869749
objOutlookMsg.BodyFormat = olText
0
 

Author Comment

by:JasonAsh
ID: 10869776
yeah can't work out the plain text bit.
0
 
LVL 2
ID: 10873048
palamangelus where are you getting the BodyFormat thing from? I can only find that in MSDN as a property of CDONTS which I don't think is related.
0
 
LVL 2
ID: 10873052
oh yeah, ta for the points Jason!
0
 
LVL 2
ID: 10873282
hmm, well after a little research, I've found that as well as a Body property, there's also a HTMLBody property suggesting that by using 'Body' the message is implicitly plain text. Still don't know how to change the setting on the email window that appears. However, you could make your own simple email dialogue without the rich text functionality and have its send button ONLY use the Body property and use the Send() method to send the message programmatically. That might be the only way to be sure.

hth

=me=
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question