Originally Posted by
June7
The error handling code always runs, even when there is no error. Need an Exit branch.
Exit_sub:
DoCmd.Close acForm, "frmBookingTheatreSearch", acSaveYes
Exit Sub
ErrorHandler:
Select Case Err
Case 2501
MsgBox "You have cancelled the email"
Resume Exit_sub
End Select
I did not know. I didn't have one on the code below:
Code:
Option Compare Database
'------------------------------------------------------------
' btnNewBookingEmail_Click
'
'------------------------------------------------------------
Private Sub btnNewBookingEmail_Click()
AlternativeName = IIf(Me.SchoolTypeID = 3, " or the Director, ", IIf(Me.SchoolTypeID = 9, " ", " or the Principal,"))
TourOrganiserORPeter = IIf(Me.MergedNameT = Null, "Name" & vbCrLf & "Manager", Me.MergedNameT & vbCrLf & vbCrLf & "Tour Organiser")
emailmsgconfirm = "Dear " & Me.MergedName & AlternativeName _
& vbCrLf _
& vbCrLf _
& "Thank you for including us in your cultural calendar. " _
& vbCrLf _
& vbCrLf _
& "The confirmation of your booking is attached as a PDF file. " _
& vbCrLf _
& vbCrLf _
& "Please sign and return it to Name by Email Fax or Post. " _
& vbCrLf _
& vbCrLf _
& "Please remember if you need to change or cancel this booking for any reason we require 28 days notice from the date of the performance and if cancelling a cancellation number will be issued at the time of cancellation." _
& vbCrLf _
& vbCrLf _
& "We trust you and your students will enjoy the performance." _
& vbCrLf _
& vbCrLf _
& "Regards" _
& vbCrLf _
& vbCrLf _
& TourOrganiserORPeter _
& vbCrLf & "Name" & vbCrLf & "address" & vbCrLf & "MARRICKVILLE NSW 2204" & vbCrLf & "Ph number" & vbCrLf & "Email email"
On Error GoTo ErrorHandler
If IsNull(Me.TeacherEmail) Or IsNull(SchoolEmail) Then
MsgBox "You require an email in the teacher email field to email the school"
'code that stops user from not filling out all required fields
ElseIf IsNull(Me!frmSubBookingsControl.Form!BookingDate) Or IsNull(Me!frmSubBookingsControl.Form!ShowsIDDrop) Or IsNull(Me!frmSubBookingsControl.Form!BookingMinimum) Or IsNull(Me!frmSubBookingsControl.Form!ShowTime1st) Or IsNull(Me!frmSubBookingsControl.Form!StatusID) Then
MsgBox "You must give a Booking Date, Show, Booking mimimum, at least one Show Time and Show Status. Please ensure you have filled these fields"
'code that sends email
Else
DoCmd.SendObject acReport, "rptNewBookingEmail", "PDFFormat(*.pdf)", TeacherEmail, SchoolEmail, , "name", emailmsgconfirm, True
Me.ConfirmationSent1st = True
Me.frmSubBookingsControl.Form![ContactName] = Me.TeacherName
Me.frmSubBookingsControl.Form![ContactSurname] = Me.TeacherSurname
DoCmd.Close acForm, "frmBookingNew", acSaveYes
End If
'This code detects error if you don't send the email and displays an alert
ErrorHandler:
Select Case Err
Case 2501
MsgBox "You have cancelled the email"
End Select
End Sub
and I never encountered that error... would love to know why