Newport Count
Active Member
- Joined
- Oct 25, 2009
- Messages
- 328
Hi,
I have built a userform that sends two emails: one email to a distribution list that details some of the entries made in the form, and another email to a specific person if a customer name has been entered that does not match an existing name from the drop-down field. This works at the moment, but I want to make the emails relevant to the outcome of an radio button on the form.
I have cobbled together the email code from various sources (Ron de Bruin and help from various sites/forums) so it may not make much sense - but it works! Therefore, I'm not confident or competent enough to adapt it to what I want it to now do.
I have added two radio buttons that answer the question (label) "Has the adjustment billed?" - Yes or No radio buttons...Yes = "optBilledYes"; No = "optBilledNo".
- I need the 1st email to be sent (details of the invoice adjustment) only if the value chosen in the radio button is 'Yes'...so If "optBilledYes"
- I need 2nd email to state if a new customer has been added to be sent regardless of the value chosen in the option button.
code is present in: Private Sub cmdSaveData_Click()
PS: I have added an extra space to the < p> & < /p> coding to display it correctly above!
I have tried many different options (mainly using If optBilledYes = True then...) but I receive debug errors which I don't know how to resolve. relating to the "If IsError" part of the 2nd email code - any help would be much appreciated!
Hopefully a simple fix (as usual!).
many thanks,
Rich
I have built a userform that sends two emails: one email to a distribution list that details some of the entries made in the form, and another email to a specific person if a customer name has been entered that does not match an existing name from the drop-down field. This works at the moment, but I want to make the emails relevant to the outcome of an radio button on the form.
I have cobbled together the email code from various sources (Ron de Bruin and help from various sites/forums) so it may not make much sense - but it works! Therefore, I'm not confident or competent enough to adapt it to what I want it to now do.
I have added two radio buttons that answer the question (label) "Has the adjustment billed?" - Yes or No radio buttons...Yes = "optBilledYes"; No = "optBilledNo".
- I need the 1st email to be sent (details of the invoice adjustment) only if the value chosen in the radio button is 'Yes'...so If "optBilledYes"
- I need 2nd email to state if a new customer has been added to be sent regardless of the value chosen in the option button.
code is present in: Private Sub cmdSaveData_Click()
Code:
Dim OutApp As Object
Dim OutMail As Object
Dim strBody As String
Dim strSignature As String
Dim strRecipients As String
Dim ws As Worksheet
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set ws = Worksheets("DropDowns")
With OutMail
.Display
End With
strRecipients = ws.Range("EmailRecipients")
strSignature = OutMail.HTMLBody
strBody = "< p style='font-family:calibri;font-size:19' >"
strBody = strBody & "Hello,"
strBody = strBody & "<br><br>I have just logged an Invoice Adjustment:"
strBody = strBody & "<br><br>Customer Name<br>" & cboCustomerName.Value
strBody = strBody & "<br><br>Invoice:<br>" & txtInvoicenumber.Value
strBody = strBody & "<br><br><br>Many thanks," & strSignature & "< /p>"
With OutMail
.To = strRecipients
.CC = ""
.BCC = ""
.Subject = "New Invoice Adjustment - " & cboCustomerName.Value & " - " & txtInvoicenumber.Value
.HTMLBody = strBody
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
If IsError(Application.Match(cboCustomerName.Value, ws.Range("CustomerName"), 0)) Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "myname@email.com"
.Subject = "New Customer added to the Adjustment Tracker - " & cboCustomerName.Value
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End If
PS: I have added an extra space to the < p> & < /p> coding to display it correctly above!
I have tried many different options (mainly using If optBilledYes = True then...) but I receive debug errors which I don't know how to resolve. relating to the "If IsError" part of the 2nd email code - any help would be much appreciated!
Hopefully a simple fix (as usual!).
many thanks,
Rich
Last edited: