Zugriff auf MsgBox für automatisierte E-Mails

Zugriff auf MsgBox für automatisierte E-Mails

Ich habe eine Access-Datenbank mit VBA-Code für eine Ja/Nein-Befehlsschaltfläche eingerichtet, um eine automatisierte Outlook-E-Mail zu senden. Wenn der Benutzer „Ja“ auswählt, wird die E-Mail geöffnet, um Anhänge zuzulassen.

Mein Problem ist, dass, wenn der Benutzer Nein auswählt, die Nachricht nicht verschwindet und die E-Mail wie angegeben gesendet wird, sondern die Frage vor dem Senden der E-Mail erneut gestellt wird, um eine zweite Antwort zu erhalten. Ich habe versucht, an verschiedenen Stellen ein „Ende“ in die zweite Hälfte des Codes einzufügen, aber nichts scheint zu funktionieren. Vorschläge wären sehr willkommen!

Code unten:

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

Antwort1

Ich habe meine eigene Frage beantwortet – ich musste lediglich den doppelten Code in meiner zweiten If-Anweisung entfernen.

MsgBox(cstrPrompt, vbQuestion + vbYesNo) =

verwandte Informationen