Avatar of Mike Rudolph
Mike Rudolph
Flag for United States of America asked on

Access freezes when user does not send email

Dear Experts,

I use the following code to send a student report to a parent:
Sub SendEmail()
       
        Dim pName As String
         pName = InputBox("Enter the parent's name", "SEND EMAIL TO PARENT")
         If pName = vbNullString Then
           GoTo Exit_SendEmail
         End If
               
        Dim School As String
        School = Nz(DLookup("SchoolName", "tblSchool"), 0)
        
        Dim TeacherName As String
        TeacherName = Nz(DLookup("teacherName", "tblTeacher"), 0)
        DoCmd.SetWarnings (False)
        Dim mailto As String
        Dim ccto As String
        Dim bccto As String
        mailto = Me.studentParentEmail
        ccto = ""
        bccto = ""
        emailmsg = "Hello " & pName & "!" & vbNewLine & vbNewLine & "Please find your child\'s student report from " & TeacherName & " at " & School & " attached!" _
        & vbNewLine & vbNewLine & "Thank you!"
        mailsub = "Recent Student Report from " & TeacherName & "at " & School

        DoCmd.OpenReport "rptStudentReport", acViewPreview, , "[studentID] = '" & [studentID] & "'"
        DoCmd.SendObject acSendReport, , acFormatPDF, mailto, ccto, bccto, mailsub, emailmsg, True
        DoCmd.Close acReport, "rptStudentReport", acSaveNo
        DoCmd.SetWarnings (True)
        

    
Exit_SendEmail:
    Exit Sub
 

 
End Sub


Private Sub cmdEmailParent_Click()
  Call SendEmail
End Sub

Open in new window


The problem that I am having is when a user closes the message dialoge box and does not 'send' the email message the application freezes and you have to hit ctrl+alt+delete to close the application. How can I capture that error and not have the application 'freeze'?

Thanks!
Microsoft Access

Avatar of undefined
Last Comment
Mike Rudolph

8/22/2022 - Mon
SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mike Rudolph

ASKER
Thanks Guys! Cbmbining both codes syntax proved to be exactly what I needed. Cheers!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes