Results 1 to 7 of 7
  1. #1
    jazzkenney is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    1

    VBA Code to report syntax errors via email


    I was curious if there was such code that will allow any users to report any syntax errors via email for troubleshooting? For example, I have an acccess database and the user might change the layout of an form when importing a file. Therefore, the user will receive an error dialog box at this point I will like for the user to be able to click on a button that will send out an automatic email to the database admin to report the error message. Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    I suppose this could be done with error handler. Code in error handler would capture the error code/message and run email procedure.
    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
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by June7 View Post
    I suppose this could be done with error handler.
    However, there is no way to print the offending line number. I've been all around the web looking for that, but the only solution I've seen is a 3rd party that does the job.

    moreover, you could use VBA' extensibility library to loop all your code and put line numbers as comment strings at the end of the every line of code you have in your project. But I'm not sure if doing that could actually help you capture the line number that was offending anyway.

    you can use extensibility in error handlers to print almost anything identifiable about errors that occur, except the line number of the error.

    there's some useful info for ya!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Quote Originally Posted by ajetrumpet View Post
    However, there is no way to print the offending line number. I've been all around the web looking for that, but the only solution I've seen is a 3rd party that does the job.

    moreover, you could use VBA' extensibility library to loop all your code and put line numbers as comment strings at the end of the every line of code you have in your project. But I'm not sure if doing that could actually help you capture the line number that was offending anyway.

    you can use extensibility in error handlers to print almost anything identifiable about errors that occur, except the line number of the error.

    there's some useful info for ya!
    Adam,
    Here's a sample that shows line number in the error handler.

    Seems ERL is undocumented, but available. I found it on the web. Try it.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : dListTables
    ' Author    : Jack  based
    ' Date      : 23-11-2011
    ' Purpose   : To list table names in database and show error handling with line number
    ' ***You MUST NUMBER Your Lines
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs: N/A
    ' Dependency: N/A
    '--------------------------------------------------------------------------
    '
    Public Function dListTables()
       On Error GoTo dListTables_Error
    
    10       On Error GoTo dListTables_Error
    
          Dim lIDX As Long
          Dim lMAX As Long
    20    lMAX = CurrentDb.TableDefs.Count
          Dim Tdx As TableDef
    30    lIDX = 0
           
    40    For Each Tdx In CurrentDb.TableDefs
    50        lIDX = lIDX + 1
    60        Debug.Print Tdx.name
    70    Next Tdx
           
    80    MsgBox "complete"
    90 Err.Raise 6788, , "This my own Custom error for demonstration"
    
    100   Debug.Print "Managed to run through " & lIDX & " records before breaking it!"
    110   Debug.Print "It claims there are " & lMAX & " tables..."
    120   Debug.Print Err.number & ": " & Err.Description
    
    130      On Error GoTo 0
    140      Exit Function
    
    dListTables_Error:
    
    150       MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure dListTables of Module AWF_Related at line: " & Erl
    
       On Error GoTo 0
       Exit Function
    
           
    End Function

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    what you posted doesn't make sense, bud.

    how could I possibly try it? I don't want to anyway, but if I did...

    on a side note to this though, I've never heard of ERL in Access nor have I researched it. But do you realize that I can take this information and basically give myself a raise at the company I work at right now?

    Every day that goes by, I think more and more that I could give up my job and just make a living off of the ignorance of other people. So, I guess thanks to the genius that posted this on the web. I sure hope he got paid (I know I will)!

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Adam,

    It was some existing code. It lists the table names in an Access database. It was part of some help with someone having a corruption problem at their end.

    My point was to show line 90 and the error handler line 150 with line numbers. Try it.

    You could just take the error routine basics, number your code, any code,
    and use err.raise to show the error handler referencing the line numbers.

    Ii was really responding to this quote of yours
    However, there is no way to print the offending line number. I've been all around the web looking for that, but the only solution I've seen is a 3rd party that does the job.

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by orange View Post
    Ii was really responding to this quote of yours
    YOU just solved the problem of capturing line numbers of errors when they occur. Or do you not realize that?

    ERL is an unknown entity that captures the last numbered code line in the current scope. So bottom line, you can take this with a combination of vba's extensibility DLL and do what the OP here requested help for.

    so congrats to you, sir!

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

Similar Threads

  1. Replies: 10
    Last Post: 07-25-2011, 12:07 PM
  2. Simple code syntax question
    By mseeker22 in forum Programming
    Replies: 1
    Last Post: 07-07-2011, 03:55 AM
  3. Replies: 4
    Last Post: 04-13-2011, 10:11 AM
  4. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 PM
  5. dialog box errors in report
    By Jane in forum Programming
    Replies: 0
    Last Post: 11-20-2008, 01:06 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