Results 1 to 11 of 11
  1. #1
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102

    Error Handling


    I have been working on a db that I feel like I have in a pretty good place. All of the basic functionality seems to be working pretty well, but I am wanting to improve the error handling capabilities of a few of my forms.

    Can anyone point me to a decent online resource for beginners that explains the fundamentals of error handling? Specifically, I am wanting to learn about message boxes for when a user leaves a null value in a required control, or tries to save a record with out filling in all the fields/controls needed for a new record.

    I am looking for something along the vein of "Access Error Handling for Dummies"

    Thanks
    Mike

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Does this help http://allenbrowne.com/ser-23a.html

    Be aware that error handler can get in the way of debugging code. Often means temporarily disabling the error handler code when tracking down cause of error.

    Data validation isn't really an 'error' that error handlers are intended to deal with. Error handlers are for run-time errors - code bugs.
    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
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    Quote Originally Posted by sprtrmp View Post
    Specifically, I am wanting to learn about message boxes for when a user leaves a null value in a required control, or tries to save a record with out filling in all the fields/controls needed for a new record.
    The easiest (not most flexible) is to make the field in the table a required field. Then there is no extra coding necessary in the forms.

  4. #4
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102
    Quote Originally Posted by JamesDeckert View Post
    The easiest (not most flexible) is to make the field in the table a required field. Then there is no extra coding necessary in the forms.
    That was how I had originally gone into it: I made the important fields "required" at the table level, and set up a validation rule (ie: a "quantity" field that is required to be greater than 0), then went back and tried to add a record (from the form) without adding a quantity, and it allowed me to add it with nothing like any kind of error, so I am not sure what is going on there.

    in a perfect world,, I would like some kind of message box to pop up if a user tries to add a record with out adding some of the required info that says something like "hey dummy, you missed something". I would also like to get rid of the access-generated runtime error message box and replace it with something "sexier" if possible, but one thing at a time.

    That is what I am looking for, anyway.

    Thanks
    Mike

  5. #5
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    Mike,
    You can have a specific requirement at the table level by using a Validation rule. So If a qty needs to be >0, your validation rule is '>0' (no apostrophes).
    Then your error msg is in the Validation Text saying "Qty must be greater than one" or something. This is not as flexible as putting the validation in your form but will work no matter if you have 5 forms based on this table, or someone tries to enter data directly into the table. This should work in combination with the required field. So if the field is not required, you don't have to put a value in. But if you do enter a value, it has to be above 0. If you make it required, then a value has to be entered.

    Replacing the access runtime errors are not hard, you just need to jump to a part of your code that displays your own error using ON ERROR GOTO SOMELABEL.

  6. #6
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102
    I have a table (called "tblAssigned) with fields for an employeeID, a productID and a quantity. In Design View for the table, I set the required property for the "quantity" field to "yes", input a validation rule of ">0", and validation text of "Enter a quantity greather then 0".

    using a form that is based on a query related to that table, I would expect this to NOT allow me to add a new record if I leave the quantity field at "0", but when the command is executed, the new record is added right to that table, even with a quantity of "0"... so, there is something that I am not doing right.

    and while I understand that replacing the runtime errors are not hard, I need some kind of resource that explains the basics of it (from the ground up) as I have absolutely no experience with it, and I am looking to learn

    Mike

  7. #7
    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,870
    June makes a good point. What you are describing is field/value validation, not error handling.
    If you make a field required, it must have a value (but it may not be a value acceptable to your business logic).
    In the before update event of the form -the last event before a record change is saved - put in any validation logic you require.

    In addition to the Allen Browne info there is also great info on error handling and debugging at Chip Pearson's site


    Good luck.

  8. #8
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102
    Thanks, that is the type of stuff I am looking for.

  9. #9
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    I just did a test and entering data at the table and at a form based on a table with the setting specified earlier works the way I said.
    I wonder if something else is going on. Could you include a pic of the field properties for the quantity field.

    BTW: is your logon name referencing the music group?

  10. #10
    sprtrmp is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    Greenville, SC
    Posts
    102
    Thanks for spending the time on it. Sorry, I went back and figured out what the problem was with that, and got it corrected (turns out, it was a completely bone-headed move on my part, and I won't explain any further to save myself the embarrassment).

    once I got my head out of my er... the clouds, I fixed that issue, and I am getting the standard runtime error box at the form level. I would like to (and I am still learning how to) do away with that message box and turn it into a "more-Windows"-y version.

    (Yes, the logon name refers to the band, I have been a HUGE fan pretty much since birth, and the first time I ever sat down at a computer and needed to come up with a login ID for ANYTHING (some time around 1990 or 1991 I think, that is what I came up with, and I have been using ever since.)

  11. #11
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    I love their music also.
    I'm glad you got it working. I couldn't imagine it working the way you said.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-06-2015, 12:06 PM
  2. Error handling of table update error?
    By panoss in forum Forms
    Replies: 5
    Last Post: 10-31-2014, 02:06 PM
  3. Error Handling Question - On Error Goto
    By redbull in forum Programming
    Replies: 7
    Last Post: 12-06-2012, 07:54 AM
  4. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  5. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 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