访问 MsgBox 以接收自动电子邮件

访问 MsgBox 以接收自动电子邮件

我有一个 Access DB,其中设置了 VBA 代码,用于“是/否”命令按钮以发送自动 Outlook 电子邮件。如果用户选择“是”,则会打开电子邮件以允许添加附件。

我的问题是,当用户选择否时,消息不会消失并按提示发送电子邮件,而是在发送电子邮件之前再次询问问题以获得第二次答复。我尝试在代码的后半部分的不同位置放置“结束”,但似乎没有任何效果。非常感谢您的建议!

代码如下:

Private Sub Command2064_Click()

Const cstrPrompt As String = _
    "Do you want to add an attachment to your audit feedback?"
If MsgBox(cstrPrompt, vbQuestion + vbYesNo) = vbYes Then

'******begin code******
Dim olApp As Object
   Dim objMail As Object

   Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open

   'Create e-mail item
   Set objMail = olApp.CreateItem(olMailItem)

'***creates and sends email
With objEmail
    With objMail
     .To = Me.Combo0 & "" & "@myemail.com"
     '.Cc = "[email protected]"
     .Subject = "Audit Correction Needed"
     .Body = Me.Text136 & "          " & "          " & Me.Combo154 & "                    " & Me.Text1677
     .Display
     End With
     End

End With
End If


If MsgBox(cstrPrompt, vbQuestion + vbYesNo) = vbNo Then

  Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
  'Create e-mail item
   Set objMail = olApp.CreateItem(olMailItem)
  '***creates and sends email
With objEmail
    With objMail
     .To = Me.Combo0 & "" & "@myemail.com"
     '.Cc = "[email protected]"
     .Subject = "Audit Correction Needed"
     .Body = Me.Text136 & "          " & "          " & Me.Combo154 & "                    " & Me.Text1677
     .send
     End With


End With


  MsgBox "Audit Correction Email has been sent. You must now select the Send to Tracking Sheet button."

End If
End Sub

答案1

我回答了我自己的问题——我所要做的就是删除第二个 If 语句中的重复代码。

MsgBox(cstrPrompt, vbQuestion + vbYesNo) =

相关内容