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!
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!