I use the following code to send a student report to a parent:
Dim pName As String
pName = InputBox("Enter the parent's name", "SEND EMAIL TO PARENT")
If pName = vbNullString Then
Dim School As String
School = Nz(DLookup("SchoolName", "tblSchool"), 0)
Dim TeacherName As String
TeacherName = Nz(DLookup("teacherName", "tblTeacher"), 0)
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
Private Sub cmdEmailParent_Click()
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'?