Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add a second optional object to open Outlook in Access VBA?
    primarykey
    data
    text
    <p>So far I have the first referral open-up the Outlook and retrieving the right email address with an automatic customized message. Now, I'm trying to add a second referral, <code>Referral_To_ID_2</code> as an optional, meaning don't raise error if it isn't selected. Below is the form and the code I have so far, but I'm not quite sure if I'm doing it right by assigning a reference to my second object, <code>Referral_To_ID_2</code> as well as the <code>If</code> statement. Now it's actually giving me an error if I don't select anything in <code>Referral_To_ID_2</code> Can anyone explain me the best way to add a second object as an optional? Many thanks! </p> <p><img src="https://i.stack.imgur.com/u1rhJ.png" alt="enter image description here"></p> <pre><code>Private Sub cmdReferralEmail_Click() Dim emailAddresses As Collection, newEmail As Email Dim emailAddresses2 As Collection, newEmail2 As Email Set emailAddresses = GetEmails(referralId:=Referral_To_ID) Set emailAddresses2 = GetEmails(referralId:=Referral_To_ID_2) If emailAddresses Is Nothing Then 'User cancelled ElseIf emailAddresses2 Is Nothing Then 'User cancelled GoTo ExitHandler ElseIf emailAddresses.count = 0 Then MsgBox "No email addresses were selected for this client.", vbExclamation Else Set newEmail = New Email Set newEmail2 = New Email With newEmail .HtmlBody = _ "&lt;p&gt;We referred a potential client to you, " &amp; _ Nz(First_Name &amp; " ", "") &amp; Nz(Last_Name, "") &amp; _ ", who needs help with an employment matter in " &amp; Nz(State, "your state") &amp; _ ". Thank you for any assistance you might be able to provide.&lt;/p&gt;" Set .MailTo = emailAddresses Set .MailTo = emailAddresses2 .Cc.Add "kjghkjgh@ihiu.com" .Subject = "Potential" .Send End With End If End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload