Email userform checkbox as subject

Antonio12

Board Regular
Joined
Jul 11, 2012
Messages
73
Hello everybody:

I created a userform that sends an email to my email box. Its very simple but it has been a pain to fix the checkbox issue I'm having. In the userform I have two checkboxes and what I want is, if I select box one, the email subject would be the one in checkbox one, if I select checkbox2, then the subject should be the text in checkbox 2.

Also, I would like to have a code that if the userform is not complete, then it displays an error and doesnt send the email.

Can anybody hel me out. Here is my code for the userform:





Private Sub CommandButton1_Click()
Unload UserForm1
End Sub
Private Sub Enviar_Click()
Dim OutApp As Object
Dim OutMail As Object


Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)


With UserForm1
cbx1 = .CheckBox1.Caption
cbx2 = .CheckBox2.Caption
txtbox1 = .TextBox1
txtbox2 = .TextBox2
End With


On Error Resume Next
With OutMail
.To = "antonio.rodrigues@rangel.pt"
.CC = ""
.BCC = ""
If cbx1.Value = True Then
.Subject = cbx1
On Error Resume Next
End If
If cbx1.Value = False Then
.Subject = cbx2
On Error Resume Next
End If
If cbx2.Value = True Then
.Subject = cbx2
End If
If cbx2.Value = False Then
.Subject = cbx1
End If
On Error Resume Next
.HTMLBody = "SL ERROR - " & vbcrf & txtbox1 & " " & vbcrf & vbcrf & txtbox2
.Send
End With
On Error GoTo 0


Set OutMail = Nothing
Set OutApp = Nothing


Unload UserForm1


End Sub


Private Sub TextBox1_Change()


End Sub


Private Sub TextBox2_Change()


End Sub


Thanks a lot guys!
 

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