Results 1 to 4 of 4
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Thumbs up Where do I put DoCmd.Close acForm, "Email_AORB"?

    I have found where to put it if the email is sent. Where do I put the command to where it would affect in both instances? Such as when the email is not sent (canceled at the email itself, or when IsNull(CR_numbers) = True.

    Private Sub Send_AORB_OOB_Click()
    On Error GoTo Error
    Dim strSubject, strBody, strAddresses As String
    DoCmd.RunCommand acCmdSaveRecord
    If IsNull(CR_Numbers) Then
    MsgBox "There are no OOB CRs te send"
    Exit Sub
    Else
    With Me
    If Not IsNull(.cbxNumber) And Not IsNull(.Priority) And Not IsNull(.Hours) Then


    strBody = strBody & "Date Issue Identified: " & Chr(9) & Chr(9) & Chr(9) & !Dates & vbCrLf & vbCrLf
    DoCmd.SendObject acSendNoObject, , acFormatTXT, strAddresses, , , strSubject, strBody, True
    End If
    End With
    Exit Sub
    DoCmd.Close acForm, "Email_AORB"
    End If
    End Sub

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Put it outside the outermost If Then End If.

    There is no error handler code so the GoTo Error is useless. The two Exit Subs are unnecessary because there is no code after the If Then that needs to be bypassed. If you want error handler:
    Code:
    Private Sub Send_AORB_OOB_Click()
    Dim strSubject, strBody, strAddresses As String
    On Error GoTo ErrProc
    DoCmd.RunCommand acCmdSaveRecord
    If IsNull(CR_Numbers) Then
        MsgBox "There are no OOB CRs to send"
    Else
        With Me
            If Not IsNull(.cbxNumber) And Not IsNull(.Priority) And Not IsNull(.Hours) Then
                strBody = strBody & "Date Issue Identified: " & Chr(9) & Chr(9) & Chr(9) & !Dates & vbCrLf & vbCrLf
                DoCmd.SendObject acSendNoObject, , acFormatTXT, strAddresses, , , strSubject, strBody, True
            End If
        End With
    End If
    ExitProc:
    DoCmd.Close acForm, "Email_AORB"
    Exit Sub
    ErrProc:
    Resume ExitProc
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    June7,
    Apologies, I didn't put the error handeling routine in there. It exists. I have found a way to close it in all circumstance by putting the command in both if routines.

    End If
    End With
    Exit Sub
    Error_Handler_Exit:
    Exit Sub
    Error:
    Select Case Err.Number
    Case 2501
    Err.Clear
    Resume Error_Handler_Exit
    Case Else
    MsgBox "Error No. " & Err.Number & vbCrLf & "Description: " & Err.Description, vbExclamation, "Database Error"
    Err.Clear
    Resume Error_Handler_Exit
    End Select
    Exit Sub
    End If
    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I did some edits on my previous post. Might look at again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. "Close form" action does not release table
    By TFisher in forum Programming
    Replies: 8
    Last Post: 10-23-2022, 11:54 AM
  2. Replies: 5
    Last Post: 09-01-2014, 12:11 PM
  3. Replies: 2
    Last Post: 07-15-2014, 07:22 PM
  4. How to disable the "close" button in Access
    By Demerit in forum Access
    Replies: 7
    Last Post: 12-08-2013, 07:08 PM
  5. Can I pass "sort by" using DoCmd.OpenReport
    By alsoto in forum Reports
    Replies: 3
    Last Post: 04-16-2009, 08:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums