Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    96
    Provided Answers: 4

    Cool Answered: Exiting from Sub after error

    Hello All

    Haven't posted here for a while because mostly I can find what I need by digging around previous posts, however this one has me stumped and I feel like it's a rookie error.

    I'm using a subroutine to launch an MS Outlook email template and I want to trap the error when/if the template doesn't exist at the specified location. Problem is that I keep getting a Label Not Defined Error on the line

    Code:
        Resume Exit_SendMailServ
    This is the code for the subroutine.

    If I leave this line out I end up with a blank message box popping up after the subroutine executes (naturally enough).

    Could one of you kind Guru's tell me where I am going wrong please.

    Code:
    Sub SendMailServ()
    On Error GoTo Err_SendMailServ
    
    Dim objOutlook As Object
    Dim objEmail As Object
    Dim EmailTemplate As String
    EmailTemplate = "C:\Access\ServiceVisit.oft"
    Set objOutlook = CreateObject("Outlook.application")
    
    Set objEmail = objOutlook.CreateItemFromTemplate(EmailTemplate)
    With objEmail
        .To = EmailAddr
        .Display
    End With
    
    Err_SendMailServ:
        MsgBox Err.Description
        Resume Exit_SendMailServ
    
    End Sub

  2. Best Answer
    Posted by sheusz

    "Told you it was a rookie error.

    Exit Sub before Error handler

    Code:
    Sub SendMailServ()
    On Error GoTo Err_SendMailServ
    
    Dim objOutlook As Object
    Dim objEmail As Object
    Dim EmailTemplate As String
    EmailTemplate = "C:\Access\MulticamServiceVisit.oft"
    Set objOutlook = CreateObject("Outlook.application")
    
    Set objEmail = objOutlook.CreateItemFromTemplate(EmailTemplate)
    With objEmail
        .To = EmailAddr
        .Display
    
    End With
    Exit Sub
        
    Err_SendMailServ:
        MsgBox Err.Description
        
    End Sub
    "


  3. #2
    Join Date
    Sep 2010
    Posts
    96
    Provided Answers: 4
    Told you it was a rookie error.

    Exit Sub before Error handler

    Code:
    Sub SendMailServ()
    On Error GoTo Err_SendMailServ
    
    Dim objOutlook As Object
    Dim objEmail As Object
    Dim EmailTemplate As String
    EmailTemplate = "C:\Access\MulticamServiceVisit.oft"
    Set objOutlook = CreateObject("Outlook.application")
    
    Set objEmail = objOutlook.CreateItemFromTemplate(EmailTemplate)
    With objEmail
        .To = EmailAddr
        .Display
    
    End With
    Exit Sub
        
    Err_SendMailServ:
        MsgBox Err.Description
        
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •