自動メール用のMsgBoxにアクセスする

自動メール用のMsgBoxにアクセスする

自動 Outlook メールを送信するための、はい/いいえコマンド ボタンの VBA コードを使用して Access DB を設定しました。ユーザーが「はい」を選択すると、添付ファイルを許可するためにメールが開きます。

問題は、ユーザーが「いいえ」を選択した場合、メッセージが消えず、プロンプトどおりに電子メールが送信されず、電子メールを送信する前に 2 回目の応答を求める質問が再度表示されることです。コードの後半のさまざまな場所に「end」を配置してみましたが、何も機能していないようです。ご提案いただければ幸いです。

以下のコード:

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

私は自分の質問に答えました。2 番目の If ステートメント内の重複コードを削除するだけで済みました。

MsgBox(cstrPrompt, vbQuestion + vbYesNo) =

関連情報