Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling

Status
Not open for further replies.

kabirpatel

Programmer
Nov 16, 2006
12
GB

I have recently upsized an Access database to SQL Server. The .adp is for the most part working fine.

However, when an end user tries to create a duplicate record in one of the Primary key columns of a Form he gets a SQL Server error message as follows:

"Violation of Primary Key constraint. Cannot insert duplicate key in object myTable".

This is obviously not a very useful error message. What would be the best way to ensure that a more meaningful error message is returned?

I have considered adding code to the "After_Update" event of the cell in question. This however seems long winded. Is there an easier option?

Thanks
Kabir
 
I tend to be proactive about validation, i.e. do all the checks before-hand rather than wait to see what errors the database returns. In this case, I would check to see if the ID already exists and return a user-friendly message if it does.

If you have some sort of "Save" button you could do this in the function the button calls. If you entirely rely on binding, a likely place to put it is in the form's Before_Insert event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top