Solved

Visual Basic 6 and Microsoft Outlook

Posted on 2004-04-20
9
344 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
9 Comments
 
LVL 2

Assisted Solution

by:taherzm
taherzm earned 62 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 63 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

775 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