通过电子邮件选择进行电子邮件发送

时间:2015-08-24 14:51:32

标签: vba email combobox access-vba

我正在尝试根据组合框选择和点击提交按钮发送电子邮件。我收到类型不匹配错误。我使用了select case,因为我将添加多个带有名称的组合框。

Dim StrEmail as String
Select Case Me.cmbOwner2

Case Is = "AV"
    If StrEmail Is Null Then
        StrEmail = "dan.moses@yahoo.com"
    Else
        StrEmail = StrEmail & "," & "dan.moses@yahoo.com"


Case Is = "ENG"
    If StrEmail Is Null Then
        StrEmail = "brianna.cates@yahoo.com"
    Else
        StrEmail = StrEmail & "," & "brianna.cates@yahoo.com"
    End If

End Select

DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "StrEmail", "", _
  "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal

1 个答案:

答案 0 :(得分:1)

有几件事:

1)避免使用strEmail = null或ifnull(strEmail)。

相反,如果strEmail =“”,或者len(strEmail)= 0

,则执行

原因:在VBA中声明String变量时,将其测试为null将返回false。所以在你的代码中,它直接跳到这一部分:

Else
StrEmail = StrEmail & "," & "dan.moses@yahoo.com"

表示您的收件人字符串以逗号开头。

2)使用分号而不是逗号作为Outlook中收件人的分隔符。