I've got a form. i've got 2 buttons that work perfectly individually, but i want to combine them.
I also only want to save the record if the email is sent. and not if they cancel the email or another error.
This is the code i've got. I hope you can point out the glaringly obvious error i am missing.
--------------------
Option Compare Database
Private Sub cmdSave_NLR_Click()
Call SendEmail
If Err.Number = 0 Then
<what am i missing here. I previously had call Sub Save_NLR but it was executing regardless of the email outcome>
End If
End Sub
Private Sub SendEmail()
On Error GoTo HandleErr
'-- The Variables are used for sending the leave request email.
Dim stRecipient As String '-- This variable will contain the primary recipient.
Dim stCC As String '-- This variable is who is included CC.
Dim stSubject As String '-- This variable is the subject line.
Dim stBody As String '-- This variable is the body of the Email.
'-- This sets the information contained in the variables.
stSubject = "UMG Leave Request is " & Status & ". ** " & stGivenName & " " & stSurname & " from Team " & CboTeamNumber
stRecipient = NLR_ApplicantName
stBody = "Your leave request for " & LeaveStartDate & " to " & LeaveEndDate & " has been " & Status & "." & Chr$(13) & Chr$(13) & _
"What you need to do next...."
DoCmd.SendObject , , acFormatTXT, stRecipient, "Jimmy@abc.com", , stSubject, stBody, -1 '-- Email command.
Exit Sub
HandleErr:
If Err.Number = 2501 Then
MsgBox "The automated email was cancelled or failed." & Chr$(13) & "Please inform the applicant of the status of this application"
Else
MsgBox Err.Description
End If
End Sub
'-- Saves the record
Private Sub Save_NLR()
On Error GoTo cmdSave_NLR_Click_Err
On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
cmdSave_NLR_Click_Exit:
Exit Sub
cmdSave_NLR_Click_Err:
MsgBox Error$
Resume cmdSave_NLR_Click_Exit
End Sub