到目前为止,我有第一个推荐人打开 Outlook 并使用自动自定义消息检索正确的电子邮件地址。现在,我正在尝试添加第二个推荐,Referral_To_ID_2
作为可选,这意味着如果没有选择它就不会引发错误。下面是我到目前为止的表单和代码,但我不太确定我是否通过分配对我的第二个对象的引用Referral_To_ID_2
以及If
语句来做对了。现在,如果我没有选择任何东西,它实际上给了我一个错误Referral_To_ID_2
谁能解释我添加第二个对象作为可选对象的最佳方法?非常感谢!
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 = _
"<p>We referred a potential client to you, " & _
Nz(First_Name & " ", "") & Nz(Last_Name, "") & _
", who needs help with an employment matter in " & Nz(State, "your state") & _
". Thank you for any assistance you might be able to provide.</p>"
Set .MailTo = emailAddresses
Set .MailTo = emailAddresses2
.Cc.Add "kjghkjgh@ihiu.com"
.Subject = "Potential"
.Send
End With
End If End Sub