[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

Visual Basic 6 and Microsoft Outlook

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
JasonAsh
Asked:
JasonAsh
2 Solutions
 
taherzmCommented:
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
 
www_SMR_co_uk_was_too_offensiveCommented:
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
 
www_SMR_co_uk_was_too_offensiveCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JasonAshAuthor Commented:
Thanks both sets of code worked.

Cheers,

Jason.
0
 
palamangelusCommented:
objOutlookMsg.BodyFormat = olText
0
 
JasonAshAuthor Commented:
yeah can't work out the plain text bit.
0
 
www_SMR_co_uk_was_too_offensiveCommented:
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
 
www_SMR_co_uk_was_too_offensiveCommented:
oh yeah, ta for the points Jason!
0
 
www_SMR_co_uk_was_too_offensiveCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now