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
 

RobertSF

Board Regular
Joined
Jun 20, 2017
Messages
104
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! :)
 

Forum statistics

Threads
1,081,556
Messages
5,359,548
Members
400,533
Latest member
fpenning

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top