Userform problem

Antonio12

Board Regular
Joined
Jul 11, 2012
Messages
73
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
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Sorry, forgot to mention another issue with this userform. When I'm sending the userform by email, the subject of the email should be the one of the checkbox selected but I'm always getting the one in checkbox2 no matter what I select.

Thanx again
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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