Solved

Visual Basic 6 and Microsoft Outlook

Posted on 2004-04-20
9
345 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…

829 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