造訪 MsgBox 以取得自動電子郵件

造訪 MsgBox 以取得自動電子郵件

我有一個使用 VBA 程式碼設定的 Access DB,用於使用是/否命令按鈕來傳送自動 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) =

相關內容