By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Automatic email with multiple lines

AllusiveKitten
P: 43
Hi all

I am trying to set up an automatic email that requires multiple lines and paragraphs.

Can someone please help me, the coding I have so far only sustains one continuous line.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. Dim Email As String
  4. Dim objOutlook As Outlook.Application
  5. Dim objEmail As Outlook.MailItem
  6.  
  7. Email = "name@company.com"
  8.  
  9. Set objOutlook = CreateObject("Outlook.application")
  10.  
  11. Set objEmail = objOutlook.CreateItem(olMailItem)
  12.  
  13. With objEmail
  14.  
  15.     .To = Email
  16.     .Subject = "Test email document"
  17.     .Body = "This is just a test"
  18.     .Send
  19. End With
  20.  
  21. Set objEmail = Nothing
  22.  
  23. End Sub
Thank you for your help
Oct 18 '07 #1
Share this Question
Share on Google+
5 Replies


Scott Price
Expert 100+
P: 1,384
You inadvertently posted your question in the Access Articles section. I have moved it across for you to the main forum.

MODERATOR
Oct 18 '07 #2

Jim Doherty
Expert 100+
P: 897
Hi all

I am trying to set up an automatic email that requires multiple lines and paragraphs.

Can someone please help me, the coding I have so far only sustains one continuous line.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. Dim Email As String
  4. Dim objOutlook As Outlook.Application
  5. Dim objEmail As Outlook.MailItem
  6.  
  7. Email = "name@company.com"
  8.  
  9. Set objOutlook = CreateObject("Outlook.application")
  10.  
  11. Set objEmail = objOutlook.CreateItem(olMailItem)
  12.  
  13. With objEmail
  14.  
  15. .To = Email
  16. .Subject = "Test email document"
  17. .Body = "This is just a test"
  18. .Send
  19. End With
  20.  
  21. Set objEmail = Nothing
  22.  
  23. End Sub
Thank you for your help

Concatenate your message into a string variable and then assign the variable to the BODY as below demonstrates:

Expand|Select|Wrap|Line Numbers
  1.  Dim mymsg as string 
  2. mymsg = "This is just a test & vbcrlf
  3. mymsg = mymsg & "This is another line" & vbcrlf
  4. mymsg = mymsg & "This is yet another line & vbcrlf & vbcrlf
  5. mymsg = mymsg & "This line has double spaced" 
  6.     .Body = mymsg
  7. .Send
  8.  
Regards

Jim
Oct 18 '07 #3

NeoPa
Expert Mod 15k+
P: 31,186
Notice the vbCRLF that's used in Jim's code. This is a Carriage Return / Line Feed sequence which essentially means a new line.
That is how it is done :)
Oct 18 '07 #4

AllusiveKitten
P: 43
Thank you both, you are a great help.
Thank you NeoPa for clarifying the meanings.
Oct 18 '07 #5

NeoPa
Expert Mod 15k+
P: 31,186
No problem AK - Glad to help :)
Oct 19 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.