根据访问VBA

时间:2015-08-21 12:36:55

标签: vba email combobox

我正在尝试根据基于四个不同组合框中的选择的命令按钮单击来获取我的访问表单电子邮件。我可以根据第一个选择来让它工作,但另一个根本没有出现在电子邮件中。为了澄清我希望能够从四个不同的组合框中选择4个不同的人,并且只向所有4个人发送一封电子邮件。

这是我到目前为止的代码(我为空间剪掉了一些代码,但这是jist)我应该在那里有一个AND:

Private Sub cmdAdd_Click()
If Me.cmbOwner2 = "AV" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "5047329", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner2 = "ENG" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "5062222", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner2 = "HGR_MGRS" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "523145", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner3 = "ED" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "8623", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner3 = "IT" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "72658", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner3 = "PS" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "597444", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
ElseIf Me.cmbOwner4 = “LMO" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "1326488", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner4 = "RVSM" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "1354968", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner4 = "RII" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "21578", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
ElseIf Me.cmbOwner5 = "LLM" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "5032415", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner5 = "ENGRR" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "86952", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
DoCmd.OpenForm "frmETIC", acNormal, , , acFormEdit, acWindowNormal
ElseIf Me.cmbOwner4 = "JAK" Then
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "231548", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
DoCmd.Close acForm, "frmETIC", acSaveNo
End If
End Sub

提前致谢!

1 个答案:

答案 0 :(得分:1)

您正在使用带有ElseIf的IF语句来检查多个数据。只要语句为TRUE,IF语句就会停止。

您可以使用Select Case执行此操作的方法之一:

Dim StrEmail As String

Select Case Me.cmbOwer2
Case Is = "AV"
    If StrEmail Is Empty Then
        StrEmail = "5047329"
    Else
        StrEmail = StrEmail & ";" & "5047329"
    End If
Case Is = "ENG"
    If StrEmail Is Empty Then
        StrEmail = "5062222"
    Else
        StrEmail = StrEmail & ";" & "5062222"
    End If
Case Is = "HGR_MGRS"
    If StrEmail Is Empty Then
        StrEmail = "523145"
    Else
        StrEmail = StrEmail & ";" & "523145"
    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

您必须为其他Select Case重复ComboBoxes StrEmail String用于收集需要通过电子邮件发送的人员。