Results 1 to 8 of 8
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Error Handling Question - On Error Goto

    Is there a way to somehow have a master error handler? My application has 40 modules with Various forms of other error handling events.



    However

    I want my application to email me when there is an error... Any error, across any module. What would be the best way of doing this? I don't need the code specifically but I need I guess the theory or just advice and guidance.

  2. #2
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I think I found a good way of doing this.... Just put a Call command in the existing error handling routines that call the mail routine.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    To the best of my knowledge, each sub/function needs to have its own error handler. You could have a function to send the email, and call it from your error handlers. You can pass the relevant info to include in the email.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I was able to get what I want by doing this. Within my current error handlers, I throw a "call Whoa" in them. This is generating an email, and sending me the Error number and Description in the email. I have the "sub Whoa" held in a separate module, and it seems to be working. The only annoying thing is The "A program is trying to send an email on your behalf" message... So I changed it to .display and the users will have to click send I guess.

    Code:
    Sub Whoa()
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
    
        With OutMail
            .To = "Email address 1"
            .CC = "Email address 2"
            .Subject = "Error Occured With LIFT - Error Number " & Err.Number
            .Body = Err.Description
            .Display '~~> Chnage this to .Send for sending the email
            '.Send
        End With
    
    
        Set OutApp = Nothing: Set OutMail = Nothing
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I've gotten around that by using CDO instead of automation, or I cheat and send it out through SQL Server.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Care to elaborate on CDO? Is that a .dll file that would need to be loaded onto the users machines?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124
    The only problem with doing some action in an error routine is "What if the code returns an error?". This can get very complicated very quickly if that happens. Would the Error routine call the error routine? I am not sure but you should test for this problem.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  2. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  3. Replies: 7
    Last Post: 12-13-2010, 03:12 PM
  4. Error Handling
    By trb5016 in forum Access
    Replies: 2
    Last Post: 08-10-2010, 08:37 AM
  5. On Error GoTo does not resume?
    By easbrandel in forum Programming
    Replies: 5
    Last Post: 04-15-2010, 04:13 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