자동 이메일을 위해 MsgBox에 액세스

자동 이메일을 위해 MsgBox에 액세스

자동화된 Outlook 이메일을 보내기 위해 예/아니요 명령 단추에 대한 VBA 코드로 설정된 Access DB가 있습니다. 사용자가 예를 선택하면 첨부 파일을 허용하는 이메일이 열립니다.

내 문제는 사용자가 아니요를 선택하면 메시지가 사라지지 않고 프롬프트에 따라 이메일을 보내는 대신 이메일을 보내기 전에 두 번째 응답을 위해 다시 질문한다는 것입니다. 코드의 후반부에 여러 위치에 "끝"을 배치해 보았지만 아무것도 작동하지 않는 것 같습니다. 제안해 주시면 감사하겠습니다!

아래 코드:

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) =

관련 정보