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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to customize "Duplicate Values" Error Message? 1

Status
Not open for further replies.

dlcook

MIS
Nov 1, 2001
12
US
When a user attempts to add a record to my database via asp if there is already a record they get the following message:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] 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.

/Scripts/post_new_data.asp, line 18


Here is my code - can you assist me with displaying my own page in a situation like this?

<%@ LANGUAGE=&quot;VBScript&quot; %>
<!--#include file=&quot;ADOVBS.inc&quot;-->
<!--#include file=&quot;IASUtil.asp&quot;-->
<%
Name = Replace(Request(&quot;Name&quot;), &quot;'&quot;, &quot;''&quot;)
Country = Replace(Request(&quot;Country&quot;), &quot;'&quot;, &quot;''&quot;)
Model = Replace(Request(&quot;Model&quot;), &quot;'&quot;, &quot;''&quot;)
Track = Replace(Request(&quot;Track&quot;), &quot;'&quot;, &quot;''&quot;)
Stime = Replace(Request(&quot;Stime&quot;), &quot;'&quot;, &quot;''&quot;)

Set Connection = Server.CreateObject(&quot;ADODB.Connection&quot;)

Connection.Open &quot;DSN=listing&quot;

SQLStmt = &quot;Insert Into stimes ( Name, Country, Model, Track, Stime) &quot;
SQLStmt = SQLStmt & &quot;VALUES ('&quot; & Name & &quot;', '&quot; & Country & &quot;', '&quot; & Model & &quot;', '&quot; & Track & &quot;', '&quot; & Stime & &quot;') &quot;

Set RS = Connection.Execute(SQLStmt)
%>
<HTML>
<HEAD>
<TITLE>Stage Time Added</TITLE>
<HEAD>
<BODY vlink=&quot;#0000FF&quot; alink=&quot;#0000FF&quot; BGCOLOR=&quot;#FFFFFF&quot;>
<BR>
<H2>
<font face=&quot;Arial&quot;>Your Stage Time Has Been Added!<BR>
</font>
</H2>
<font face=&quot;Arial&quot;>
<BR>
<A HREF=&quot;/Scripts/rtrank.asp&quot;><font size=&quot;2&quot;>View Rally Trophy Rank Data</font></A><font size=&quot;2&quot;>
</font> </font>
</BODY>
</HTML>
<% Connection.Close %>
 
you could do it in two ways:
1) use a stored procedure with conditions
2) do a select on the field you want to be unique and check if the recordset returned isn't empty. if it's empty it means the record doesn't exists. if it's not, the record exists and you could show your custom message.

there's an article on aspfaqs.com which explains both ways:
(-:
 
...So with the 2nd option you describe above I could use just one form to add or update a record, correct? If the recordset returns empty I could use code to add and if it's already got a record I could use code that updates(?)

Heading over to ASPFAQ's right now!

David Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top