Handling SQL Errors in MS Access

  • Hi.

    I have a SQL Server 2005 database with a MS Access (2003) UI - an MS Access adp project. I want to be able to handle the often obsurure messages which come from SQL Server and translate them to messages that my users can understand. For example, I want to translate something like;

    "The DELETE statement conflicted with the REFERENCE constraint "FK_Field_to_Region". The conflict occured in the database "CRMMS", table "dbo.Coal_Field", Column 'Region_DBKey'."

    to...

    "You can't delete a Region record if it has one or more associated Fields"

    How do I do that in MS Access?

    I know that the error from SQL Server triggers the OnError event of the form I just don't know how to read the details of the error so that I can make the correct translation.

    Thanks in advance for any help that anyone can provide.

  • Probably not the answer you want to hear but my suggestion would be to use a development language that was intended to create a UI instead of a DBMS that happens to have a rudimentary version of a UI tacked on. This implementation is generating a lot of unneccesary overhead. You have to fire up the Access DBMS and the VB runtime to then ignore Access. That being what it is you can probably check for this type of situation in the button click event and then put the message on screen. Otherwise you will likely have to create an error handler for the button click event. This is all VBA and really has nothing at all to do with SQL Server except that you are connecting to it. 🙂

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply