Solved

Visual Basic 6 and Microsoft Outlook

Posted on 2004-04-20
9
342 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
 

Author Comment

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

Cheers,

Jason.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fix34  challenge 9 97
Using YubiKey with REST API application 2 80
Fibonacci challenge 11 82
countAbc challenge 9 49
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now