Results 1 to 5 of 5
  1. #1
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60

    Error Handling for newbie

    I am having a hard time with this.

    I am trying to simply get SOMETHING to happen when a runtime error occurs.

    I have the following code that sends an email in vba:

    Code:
     
    Private Sub EmailBrenda_Click()
    Dim strMsgTxt As String
    strMsgTxt = "body text"
    DoCmd.SendObject acSendNoObject, , , "test@test.com", , , "subject", strMsgTxt, True
    On Error GoTo Err_EmailBrenda_Click
     
    
     
     
    Exit_EmailBrenda_Click:
        Exit Sub
    Err_EmailBrenda_Click:
        If Err.Number = "2501" Then
            MsgBox "Cancelled"
        Else: MsgBox "Err.Description"
            End If
        
        
        Resume Exit_EmailBrenda_Click
    This should show a message box "instead of a runtime error" that says the message was canceled. I can't get the error handler to do anything. I have tried just a simple msgbox instead of all the if err.number etc. but not even that is getting picked up. Is the onerror wrong? why wont this work?



    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I think the problem is here (the error is numeric):

    If Err.Number = 2501 Then

    Here's a primer:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60
    oops, I actually originally had it numeric, but forgot to change it back before pasting the code in here. I just thought it was worth a shot to try with quotes.

    Thanks for the reply. Any other problems you see in there?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Actually yes, I didn't notice this earlier. The "On Error" line should be above your code. Typically it appears immediately after the declarations ("Dim...").
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    yep, I also think its the placement of the On Error. If I'm not mistaken, it will only apply to errors that occur AFTER the On Error. Put it before the actions and see if it works.

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

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2010, 08:53 AM
  2. Handling dates in queries
    By mrk68 in forum Access
    Replies: 4
    Last Post: 03-23-2009, 06:35 AM
  3. Replies: 0
    Last Post: 03-05-2009, 12:27 PM
  4. newbie questions
    By bigmac in forum Access
    Replies: 0
    Last Post: 10-07-2008, 12:53 AM
  5. Newbie question
    By The_Dude in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 07: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