Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    PSSMargaret is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    55

    Change Text of System Error Message

    I would like to change the text of a what I think is a system error message.



    I have a delete button on a form and when it's clicked for values that are in use in the database, the message
    "The record cannot be deleted or changed because table ‘|’ includes related records." is displayed.

    I think that it's error message 3200.

    How can I bypass this text and insert something more meaningful to the user?

    I am using Windows/Access 2019.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Margaret,

    Here's a link and example that you could adapt for your Custom Error(s).

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,402
    You get this message bacause other tables (child tables) contain records with foreign keys pointing to this record (Parent). So if the Parent were deleted, the records in the Child tables would be "orphans". Access won't allow this.
    There are a couple of approaches that you can take, depending on what outcome you wish. If it would be OK to delete the Child records when the Parent record is deleted, you can check "cascade deletes" in the relationship property.
    If you simply want to avoid the error message event, then before executing the delete, DLookup the Parent record key in the Child table, and if it exists, don't attempt the delete.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,776
    It's not uncommon to see a reply wrt to deleting records that usually it's not a great idea and that archiving them is typically considered a better approach.
    Consider it said.
    Access won't allow this.
    - only if there is a relationship established between the tables.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    PSSMargaret is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    55
    davegri,

    Thanks for your reply. I do understand the message and don't want to avoid it. Just want to change the text of the message to something more meaningful to the end user, e.g. "This value cannot be deleted because it has been populated in existing records." Or something similar.

    The end user won't understand parent/child tables.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,402
    ust want to change the text of the message to something more meaningful to the end user, e.g. "This value cannot be deleted because it has been populated in existing records." Or something similar.
    Then use the DLookup to determine if a child exists. If so, don't try to delete the parent. Inform the user with whatever you wish.

    Micon
    - only if there is a relationship established between the tables.
    Of course. The problem won't occur if no relationship exists.
    Last edited by davegri; 11-16-2019 at 11:02 AM. Reason: sp

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,973
    Margaret

    In your error handling routine just do something like this

    Code:
    Err_Handler:
    If err=3200 Then 
    MsgBox "Your custom message here", vbExclamation, "Message title
    Else
    MsgBox "Error " & err & " in YourProcedureName: " & err.Description
    End If
    Resume Exit_Handler
    Last edited by isladogs; 11-17-2019 at 07:26 AM.
    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
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,402
    Colin, I was going to suggest that originally (because that is what I would have done), but I have seen some posters criticizing the use of error handlers to code around preventable errors.
    You gotta try and dodge bullets around here...

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,776
    Quote Originally Posted by davegri View Post
    Colin, I was going to suggest that originally (because that is what I would have done), but I have seen some posters criticizing the use of error handlers to code around preventable errors.
    Some get too anal about it I think. Is it loftier to write a dozen lines of code to check and therefore prevent something from happening than it is to anticipate an error and trap with one line? Especially if you should have an error handler anyway? I don't think so and think it's a judgement call that depends on the situation.
    One can always make such suggestions and qualify them with comments like 'some say...' or whatever. That's how I try to cover my butt.

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,402
    Micron, good thinking.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  12. #12
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,402
    Orange, I've been using Browne's example for more than 20 years. Great routine and it logs errors to a table!

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,973
    Whilst I agree that its always better to avoid errors occurring, in my opinion its also appropriate to use error handling to cover known possible errors to ensure the application runs smoothly
    For example error 2501 when opening a report with no data, error 5 when cancelling a file browse dialog
    .
    In this case, as both of you had already covered the error avoidance, I covered the other part.
    Of course then there are the unknown errors .... those we don't know are likely to occur
    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

  14. #14
    PSSMargaret is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    55
    Thank you. This was very helpful and what I was looking for.

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,973
    We were all pleased to assist.
    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

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-25-2017, 09:24 PM
  2. Replies: 1
    Last Post: 07-26-2016, 06:34 AM
  3. Replies: 14
    Last Post: 03-31-2015, 05:20 PM
  4. Change error message for dupicate entry
    By Amber in forum Forms
    Replies: 3
    Last Post: 03-12-2012, 02:39 PM
  5. Replies: 1
    Last Post: 12-02-2010, 03:04 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