Hope somebody can help me out...
I created a userform to send the information in it via outlook. It works "fine" but I would like to change two things and it has been complicated.
The userform has 2 textboxes and 2 checkboxes. I need the userform to display an error if 1 of the textboxes has no information and if no checkbox is checked. Right now, it displays the error if the checkboxes are not selected but it still sends the email.
My problems is that the userform will always send the email even if i dont check anything. Also another problem is that the text from the first textbox is glued to the textbox 2 in the email. Here's the code I've been using.
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 = "antonios@r.pt"
.CC = ""
.BCC = ""
If cbx1.Value = True Then
.Subject = cbx1
End If
If cbx2.Value = True Then
.Subject = cbx2
End If
If CheckBox1.Value = False And CheckBox2.Value = False Then
Enable = True
MsgBox "You must check one of the boxes"
End If
.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
I created a userform to send the information in it via outlook. It works "fine" but I would like to change two things and it has been complicated.
The userform has 2 textboxes and 2 checkboxes. I need the userform to display an error if 1 of the textboxes has no information and if no checkbox is checked. Right now, it displays the error if the checkboxes are not selected but it still sends the email.
My problems is that the userform will always send the email even if i dont check anything. Also another problem is that the text from the first textbox is glued to the textbox 2 in the email. Here's the code I've been using.
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 = "antonios@r.pt"
.CC = ""
.BCC = ""
If cbx1.Value = True Then
.Subject = cbx1
End If
If cbx2.Value = True Then
.Subject = cbx2
End If
If CheckBox1.Value = False And CheckBox2.Value = False Then
Enable = True
MsgBox "You must check one of the boxes"
End If
.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