The code executes perfectly to run the email, but doesn't close the form afterwards. Thanks.
OutlookMicrosoft AccessVBA
Last Comment
Jason Steward
8/22/2022 - Mon
Shaun Kline
For your IF statements, if you do not want the user to continue, use the Exit Sub in the IF, and then End IF:
If IsNull(Me.txtChargeCode.Value = True) And Me.cboMancamp.Value > 0 Then MsgBox "You must enter an AFE, Work Order, or Cost Center", vbOKOnly, "CHARGE CODE REQUIRED" Exit SubEnd If
You have a jump point (line) for the error handler, but you do not have an On Error Goto statement at the beginning of the subroutine.
Finally, the Close Statement occurs after a Resume statement with a jump point (line) which prevents the close statement from running.
John Tsioumpris
The Docmd.Close exists only in the Error Handler which is never reached because of the Exit Sub mentioned by the other Expert...an idea would be to extract the code to a function that returns a boolean ...if everything went fine..then Docmd.Close ...else report back what went wrong
Jason Steward
ASKER
So is this what I need to do?
Me.Dirty = FalseIf IsNull(Me.txtChargeCode.Value = True) And Me.cboMancamp.Value > 0 Then MsgBox "You must enter an AFE, Work Order, or Cost Center", vbOKOnly, "CHARGE CODE REQUIRED"ElseIf Me.cboMancamp.Value > 0 And IsNull(Me.txtStartDate.Value = True) Then MsgBox "You must enter an arrivial and check-out date", vbOKOnly, "LODGING DATES REQUIRED"ElseIf Me.cboMancamp.Value > 0 And IsNull(Me.txtEndDate.Value = True) Then MsgBox "You must enter an arrivial and check-out date", vbOKOnly, "LODGING DATES REQUIRED"ElseExit SubEnd IfEnd IfEnd IfDoCmd.RunCommand acCmdSaveRecord
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Jason Steward
ASKER
John, how do I change the code below to trigger a close?
exit_Error_handler: On Error Resume Next Set objOutlook = Nothing Set objMailItem = Nothing Exit Suberr_Error_handler: Select Case Err.Number Case 287 MsgBox "Canceled by user.", vbInformation Case Else MsgBox "Error " & Err.Number & " " & Err.Description End SelectResume exit_Error_handlerDoCmd.Close acForm, "FieldVisitBookingEntryF"
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
I was thinking the last action would need to happen at the bottom without thinking about how it was actually executing. Thanks for correcting that. Your code change solution worked perfectly! Thanks so much!
Open in new window
You have a jump point (line) for the error handler, but you do not have an On Error Goto statement at the beginning of the subroutine.
Finally, the Close Statement occurs after a Resume statement with a jump point (line) which prevents the close statement from running.