sending email of user form details

donny1shot

New Member
Joined
Mar 8, 2018
Messages
18
Hi all,
I am trying to send multiple sections of my userform as email the current code I am using (below) works but if I try and add more code in to add say SYSTEM 2 DETAILS it would no longer show SYSTEM 1 DETAILS on the email and just the latter.

Private Sub CommandButton1_Click()
Dim sMessage As String, sHeading As String

' Check for valid data on the user form
'...

'Compile the message body:
sMessage = "SYSTEM 1 DETAILS:" & vbCrLf
sMessage = sMessage & "System: " & ComboBox1 & vbCrLf
sMessage = sMessage & "Height: " & ComboBox4 & vbCrLf
sMessage = sMessage & "Posts: " & TextBox1 & vbCrLf
sMessage = sMessage & "Panels: " & TextBox2 & vbCrLf

sMessage = "SYSTEM 2 DETAILS:" & vbCrLf
sMessage = sMessage & "System: " & ComboBox8 & vbCrLf
sMessage = sMessage & "Height: " & ComboBox9 & vbCrLf
sMessage = sMessage & "Posts: " & TextBox13 & vbCrLf
sMessage = sMessage & "Panels: " & TextBox15 & vbCrLf


sHeading = "NSD REQUEST " & Date

Mail_workbook_Outlook sHeading, sMessage

End Sub



'--------------------------------------------
Sub Mail_workbook_Outlook(sSubject As String, sBody As String)
'--------------------------------------------
Dim OutApp As Object
Dim OutMail As Object
Const sTo As String = "my email"
Const sCC As String = ""


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = sTo
.CC = sCC
.BCC = ""
.Subject = sSubject
.body = sBody
'.Attachments.Add
.Importance = 2
.Send
End With

'clean up
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hey, fortunately this is simple.

Code:
[COLOR=#333333]Private Sub CommandButton1_Click()[/COLOR]
[COLOR=#333333]Dim sMessage As String, sHeading As String[/COLOR]

[COLOR=#333333]' Check for valid data on the user form[/COLOR]
[COLOR=#333333]'...[/COLOR]

[COLOR=#333333]'Compile the message body:[/COLOR]
[COLOR=#333333]sMessage = "SYSTEM 1 DETAILS:" & vbCrLf[/COLOR]
[COLOR=#333333]sMessage = sMessage & "System: " & ComboBox1 & vbCrLf[/COLOR]
[COLOR=#333333]sMessage = sMessage & "Height: " & ComboBox4 & vbCrLf[/COLOR]
[COLOR=#333333]sMessage = sMessage & "Posts: " & TextBox1 & vbCrLf[/COLOR]
[COLOR=#333333]sMessage = sMessage & "Panels: " & TextBox2 & vbCrLf[/COLOR]

[COLOR=#ff0000]sMessage = "SYSTEM 2 DETAILS:" & vbCrLf ' <------------check this line[/COLOR]
[COLOR=#333333]sMessage = sMessage & "System: " & ComboBox8 & vbCrLf[/COLOR]
[COLOR=#333333]sMessage = sMessage & "Height: " & ComboBox9 & vbCrLf[/COLOR]
[COLOR=#333333]sMessage = sMessage & "Posts: " & TextBox13 & vbCrLf[/COLOR]
[COLOR=#333333]sMessage = sMessage & "Panels: " & TextBox15 & vbCrLf[/COLOR]


[COLOR=#333333]sHeading = "NSD REQUEST " & Date[/COLOR]

[COLOR=#333333]Mail_workbook_Outlook sHeading, sMessage[/COLOR]

[COLOR=#333333]End Sub[/COLOR]

Do you see it?

The line should be
Code:
sMessage = sMessage & "SYSTEM 2 DETAILS:" & vbCrLf

Stuff like this bites us all the time! :)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top