locked
Error handling RRS feed

  • Question

  • Public Function fnSendEmail()
    Dim olApp As Outlook.Application
    Dim olmail As MailItem
    Set olApp = New Outlook.Applicaiton
    Set olmail = olApp.createitem(olmailitem)
    With olmail

    .To = "myemail"
    .Subject = "test"
    .body = "Did this shit work"

    .display
    End With
    Set olmail = Nothing
    Set olApp = Nothing

    End Function

       

    Thursday, December 27, 2012 4:43 PM

Answers

  • Hello,

    If you add code after THEN, then END IF not needed.

    Use:

         If dtEnd - dtStart > 7 Then GoTo EMAIL_CREATOR
    (no end if)

    or

      If dtEnd - dtStart > 7 Then

           GoTo EMAIL_CREATOR
       End If

     I suggest using second format.

    Nadia 

    • Proposed as answer by Paolo_S Friday, December 28, 2012 8:47 AM
    • Marked as answer by Dummy yoyo Friday, January 4, 2013 6:53 AM
    Thursday, December 27, 2012 4:54 PM

All replies

  • So I am new to VBA coding first of all, so please be patient. I am trying to write in some error handling into module base on certain parameters. Basically if one of the conditions is found I want it to send me an email saying that. So far this is what I have, I am getting the error message end if without a block if. Not sure what that means. Also, can someone vet my function to make sure I wrote that correctly.

    Error handling:

    On Error GoTo EMAIL_CREATOR

    If dtEnd - dtStart > 7 Then GoTo EMAIL_CREATOR
    End If


    If startdate <= Date Then GoTo EMAIL_CREATOR
    End If
    'this is my error check for dates'

    fnSendEmail

     ******This is part of a lot of code that will loop through a share point form and create folders based on what was entered.

    Function created to send mail:

    Public Function fnSendEmail()
    Dim olApp As Outlook.Application
    Dim olmail As MailItem
    Set olApp = New Outlook.Applicaiton
    Set olmail = olApp.createitem(olmailitem)
    With olmail

    .To = "my email"
    .Subject = "test"
    .body = "Did this work"

    .display
    End With
    Set olmail = Nothing
    Set olApp = Nothing

    End Function

       

    Thanks for the help!

    • Merged by Dummy yoyo Friday, December 28, 2012 9:53 AM Merge for better support.
    Thursday, December 27, 2012 4:46 PM
  • Hello,

    If you add code after THEN, then END IF not needed.

    Use:

         If dtEnd - dtStart > 7 Then GoTo EMAIL_CREATOR
    (no end if)

    or

      If dtEnd - dtStart > 7 Then

           GoTo EMAIL_CREATOR
       End If

     I suggest using second format.

    Nadia 

    • Proposed as answer by Paolo_S Friday, December 28, 2012 8:47 AM
    • Marked as answer by Dummy yoyo Friday, January 4, 2013 6:53 AM
    Thursday, December 27, 2012 4:54 PM
  • All I see is that Application is spelled incorrectly.

    Set olApp = New Outlook.Applicaiton


    Chris Ward

    Thursday, December 27, 2012 8:33 PM
  • Hi Monique,

    Is there a question with your post?


    -Tom. Microsoft Access MVP

    Friday, December 28, 2012 3:27 AM
  • Hi Monique at the Depot,

    Welcome to the MSDN forum.

    How is it going with the problem based Nadia's suggestion?

    Please feel free to let us know if you need any help.

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 31, 2012 7:41 AM