Results 1 to 8 of 8
  1. #1
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206

    Error Logging and testing

    I'm getting closer with my database, inventory with search and projects for electronics parts. I've added Audit file and Error Log from Allen Brown's web page. What would be the way to test for errors, or to test if error log is working? Is there code to insert to test for errors. Function LogError
    Thanks,


    Tom

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    You can easily raise errors for testing purposes by inserting e.g. err.Raise 94 (which is invalid use of null) anywhere in your code
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206
    Very nice, all worked as expected, and error was logged. Now I can do some testing and add the error handler to more Subs. I see you can add any number you want to the
    err.Raise xxx statement.
    Thanks!
    Tom

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    That will raise errors from things that you can think of/envision. You might want to give a beta version to someone you know who is either adept at trouble shooting, or is darn near banned from using a computer. They will do things you might not think of. F'rinstance, if you asked me to try to break your db I would put "dog" in a date field. Not necessarily would anyone do exactly that, but they might enter a value in a field that doesn't conform, such as a malformed date in a date field or decimal in an integer field, etc. etc.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I suggested err.Raise so you could test your error logging procedures...not so you could try out all the known errors.
    Agree with Micron that the approach should be to test extremely thoroughly then pass on to others to do the same.
    Then fix known errors as far as possible and use error handling where appropriate
    For example if a user cancel a dialog box on a browse button, error 5 occurs so handle that
    Error 2501 occurs may occur when opening a report with no data

    The VBE Options should normally be 'Break on Unhandled Errors'
    However to assist with testing, it can be useful to use 'Break On All Errors' but make sure you don't release a product with that option

    BTW if you want a complete list of Access errors (over 3000 in A2016), see these links:
    http://www.mendipdatasystems.co.uk/a...des/4594398126 and http://www.mendipdatasystems.co.uk/a...ist/4594424099
    To help thorough testing
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    MadTom's Avatar
    MadTom is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    CT and VT
    Posts
    206
    Under the same question, I would like to know if a unquie name for your ErrorHandler is a good pratice or not. I have read many pages and believe I saw it some where. Also when to use On Error goto ErrHandler or On Error Resume. I know some Subs need and may encounter errors with data input. How about short Subs that may do some simple change?
    Thanks,
    Tom

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I add error handling to almost all procedures with the exception of e.g. single line functions like GetUserName or GetVersion etc

    Some developers use unique names in each procedure
    I don't because the error message includes the procedure name
    Here's a typical example

    Code:
    Private Sub cmdPrint_Click()
    
    
    On Error GoTo Err_Handler
    
    'code here
    
    
    Exit_Handler:
        Exit Sub
    
    
    Err_Handler:
    "handle error 2501 to prevent message where report has no data
        If Err.Number = 2501 Then Exit Sub
        MsgBox "Error " & Err.Number & " in cmdPrint_Click procedure : " & Err.Description
        Resume Exit_Handler
        
    End Sub
    Although there are times when it can be useful, you should normally avoid using Resume Next.
    If you have an addin like MZ Tools you can add line numbers to procedures to help pin down exactly where the error occurs.

    Hope that helps
    Last edited by isladogs; 01-07-2020 at 12:04 PM. Reason: Spelling
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    The scope of an error handler name is limited to the procedure so there is no need to have unique names. I use exactly the same code wherever needed. I once wrote a public handler that took the err number and description as arguments for routine cases that could be handled in a select case block rather than repeat the same lines of code in every procedure.

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

Similar Threads

  1. Replies: 4
    Last Post: 06-01-2018, 12:50 AM
  2. Replies: 4
    Last Post: 04-14-2015, 12:51 PM
  3. How to record time logs after logging in and logging out
    By annayanagi014 in forum Programming
    Replies: 1
    Last Post: 02-18-2015, 07:52 AM
  4. Error 32002 when logging in to access
    By chaswil69 in forum Access
    Replies: 5
    Last Post: 02-04-2015, 11:06 AM
  5. Testing
    By alansidman in forum General Chat
    Replies: 5
    Last Post: 10-24-2013, 03:58 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