Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My program reads through a list of people, if they are marked for a Maintenance for example it pulls a query and sets a recordset to that query with:</p> <pre><code>strSQL = "SELECT Email FROM Employees WHERE '" &amp; department &amp; "' = Department" Debug.Print strSQL 'I do this so I can see what my query is in the immediate window Set myR = CurrentDb.OpenRecordset(strSQL) </code></pre> <p>Then when the recordset has been made, I loop through each record that matched the criteria in the query and add the to the <code>olTo</code> of the email.</p> <pre><code>Do While Not myR.EOF Debug.Print myR!Email 'print the email of the record I'm on Set appOutlookRec = .Recipients.Add(myR!Email) appOutlookRec.Type = olTo myR.MoveNext Loop </code></pre> <p>But to answer your question more specifically, I would add two <code>IF</code> statements checking first if <code>Referral_To_ID_2</code> is null.</p> <pre><code>If Referral_To_ID_2 = Null Then 'or if its a string then If Len(Me.Notes &amp; vbNullString) = 0 'do nothing Else Set emailAddresses2 = GetEmails(referralId:=Referral_To_ID_2) End if </code></pre> <p>then put the second if down where you <code>Set .MailTo</code></p> <pre><code>If emailAddresses2 = Nothing then 'I think that's how that would go, not 100% 'do nothing Else Set .MailTo = emailAddresses2 End if </code></pre> <p>No please know that I'm no guru. I've tried to piece this together with my knowledge I've picked up on so if anyone reads this and can modify it better then have at it. Let me know how it goes.</p>
 

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