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!

Showing friendly messages while restricting duplicate Primary Keys.

Status
Not open for further replies.

mnongkhlaw

Programmer
Feb 22, 2002
62
0
0
IN
Dear Folks,

I have an ASP page using OLEDB connection to an Access database, a command object to a table (vendor) with fields Vendor_ID and Vendor_Name. Vendor_ID has been defined as a primary key in the table. I use the FormManager DTC to manage Adds,Edits and Deletes. When I test the page by Adding a duplicate primary key and clicking Save button, I get :

Error Type:
Microsoft JET Database Engine (0x80004005)
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
/hardware/_ScriptLibrary/Recordset.ASP, line 311

How do I display a friendly message in lieu of the above and then return the user to the page's Add Mode again?

Please help.

Mark

 
Thanks, MerlinB, but the question is how do I do it? For example, I've added the following code to the head portion of my ASP to check for nulls, but when "Save" button is clicked, it just shows only the Jet error message (the code does not fire at all):-
<SCRIPT LANGUAGE=javascript>
<!--
function thisPage_onbeforeserverevent(obj,event){
if (obj==&quot;cmdSave&quot;)
{if(event==&quot;onclick&quot;)
{if(Trim(thisForm.txtVendorID.value) == &quot;&quot;)
{alert(&quot;Vendor ID cannot be blank!&quot;);
thisPage.cancelEvent = true;
document.thisForm.txtVendorID.focus();
}}}}
//-->
</SCRIPT>

Is there a problem with the above code?

Mark.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top