Results 1 to 13 of 13
  1. #1
    niktsol1978 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    12

    Error trapping ms access

    Hello, everybody. I would like to ask some questions about error trapping in MS Access. Suppose i have a table, and i set up an index for a specific field to non duplicates. While i am in data enter mode, in a form, i use the Form Error event to trap the duplication. Is this a good method or while the database grows up, the speed will be decreased eventually? I have seen many database examples over the internet in which the duplication is checked through a dlookup function.

    Which way is better and more robust in terms of speed ?

    Thank you in advance

  2. #2
    Uncle Gizmo is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    26
    Quote Originally Posted by niktsol1978 View Post
    While i am in data enter mode, in a form, i use the Form Error event to trap the duplication
    It's not considered good practice to rely on an error event to control something that happens in your code, something that you can can control in a different way.

    Mind you it's usually the easiest way, and you will find that most people do it!

    I've seen examples on Allen Brownes website that use error code to control things, which was a bit of a surprise.

    Bearing in mind what I said above, the correct way to do it is to check to see if the record already exists in the table. Programmers often prefer this method because they can provide their own error message instead of the default error message supplied by MS Access which can be a bit obscure.

    Sent from my Pixel 3a using Tapatalk

  3. #3
    niktsol1978 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    12
    Yes, to be honest i was thinking the same idea myself.I also thought the same thing in the relationships. I don't use the relationship window,i create on the fly the relationships between two tables (inner, left, right joins) and control the correct data integrity through form data entry. Besides, i think that the Enforce Referential Integrity options for delete-updates cascades are not available in linked tables are they?

    Anyway, thanks for the immediate and instant answer!!

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    The main purpose of using relationships is to enforce referential integrity.
    If you do create a relationship, the join will automatically be shown in queries but it can be modified.

    Relationships are created in the source database. Trying to create a relationship/RI in the FE for a linked table will not work.
    I have an extended article on this topic at http://www.mendipdatasystems.co.uk/r...ps1/4594533224
    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

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    IMHO it would be best to use the forms BeforeUpdate event to validate the data. If the proposed data is invalid then a message can be displayed to the user and the update can be cancelled.

    Sorry. Posted this in the wrong thread
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In my view, error trapping is for unknown/unexpected errors. Things you can anticipate, like duplicate records, I would test for in my code. One advantage is that you can alert the user right away, rather than after they've entered a bunch of other data and tried to save the record. That's not to say I wouldn't have relationships/referential integrity. I would, they're just the last line of defense.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Hmm. I've always thougt Referentail Integrity was my first line of defense against inconsistent data linkages.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by davegri View Post
    Hmm. I've always thougt Referentail Integrity was my first line of defense against inconsistent data linkages.
    For you it may be, or maybe it's semantics. I prefer to try to catch issues during data entry than let an error occur when they try to save the record. Sometimes the error messages from the database engine are too cryptic for the user to understand. I consider it the last line of defense because I'll have tried to stop things from getting to that point first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    niktsol1978 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    12
    In generall, MS Access has a lot of guidance-wizards for many issues, including error message etc. Personally i prefer using the relationship window, mostly for graphical representation of the related tables in order to verify with the x client that the project runs to the desired destination. I had some novice friends of mine that mostly used wizards, having no idea from VBA etc. I like to make the parameteres myself. Mostly it depends from the design. Guys, i wanna thank you for the instant replies.I haven't been involved with Access since mid 90s (oh yes Access Basic the father of VBA, for the older here to recall), but i had the same principles in coding.

    I am starting again the research for create a large App on Access with Jet DB Engine as a back end for now, with future purporse the migration to a SQL Server. Thanks again and i am looking forward to post new threads with my project

  10. #10
    niktsol1978 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    12
    Quote Originally Posted by isladogs View Post
    The main purpose of using relationships is to enforce referential integrity.
    If you do create a relationship, the join will automatically be shown in queries but it can be modified.

    Relationships are created in the source database. Trying to create a relationship/RI in the FE for a linked table will not work.
    I have an extended article on this topic at http://www.mendipdatasystems.co.uk/r...ps1/4594533224

    What about if the tables are linked from another RDBMS like SQL Server for example?
    What about the case

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Quote Originally Posted by niktsol1978 View Post
    What about if the tables are linked from another RDBMS like SQL Server for example?
    What about the case

    Did you mean to write more than this?

    The situation is exactly the same whether it’s an Access BE or a SQL Server BE
    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

  12. #12
    niktsol1978 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    12
    Quote Originally Posted by isladogs View Post
    Did you mean to write more than this?

    The situation is exactly the same whether it’s an Access BE or a SQL Server BE

    I think that if i link the table from the DB created in SQL Server, to MS Access FE then in relationship window the Referential Integrity options are not available. I tried it a couple of years ago. If there is any improvements or changed something in later versions, please let me know

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Referential integrity is always set in the BE whether that is SQL Server or Access based
    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

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

Similar Threads

  1. Error trapping problem in subform
    By dgmdvm in forum Programming
    Replies: 9
    Last Post: 07-14-2019, 10:37 AM
  2. error trapping on a subform
    By dgmdvm in forum Forms
    Replies: 4
    Last Post: 08-24-2018, 02:52 PM
  3. Append query error trapping
    By tpcervelo in forum Programming
    Replies: 4
    Last Post: 12-22-2011, 10:57 AM
  4. Proper Error Trapping
    By SemiAuto40 in forum Programming
    Replies: 6
    Last Post: 08-11-2011, 10:22 AM
  5. Form and Subform error trapping
    By usmcgrunt in forum Forms
    Replies: 8
    Last Post: 09-12-2010, 11:54 AM

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