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

Customized Error message

Status
Not open for further replies.

Ammodog

Technical User
Dec 13, 2002
97
0
0
US
I want to customize an error message when the users register with the same login name and there is a duplicat. Can anyone tell me how to do this. As of right now they are getting the message: I would prefer to redirect it to another page. Thank you

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.


Christopher Abney
There is no limit to the good you can do if you dont care who gets the credit
 
Here is the code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/FIT.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "frmreg") Then

MM_editConnection = MM_FIT_STRING
MM_editTable = "tblregistration"
MM_editRedirectUrl = "success.asp"
MM_fieldsStr = "cause|value|first|value|mi|value|last|value|email|value|address|value|
city|value|state|value|zip|value|sslast|value|hphone|value|wphone|value|
wext|value|tanf|value|specialmem|value|login|value|password|value|select|
value|answer|value|sfirst|value|smi|value|slast|value"
MM_columnsStr = "cause|',none,'|first|',none,'|mi|',none,'|last|',none,'|email|
',none,'|address|',none,'|city|',none,'|state|',none,'|zip|',none,'|
sslast|',none,'|hphone|',none,'|wphone|',none,'|wext|',none,'|tanf|
none,1,0|specialmem|',none,'|login|',none,'|password|',none,'|
secretquest|',none,'|answer|',none,'|sfirst|',none,'|smi|',none,'|
slast|',none,'"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","'") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim rsstate
Dim rsstate_numRows

Set rsstate = Server.CreateObject("ADODB.Recordset")
rsstate.ActiveConnection = MM_FIT_STRING
rsstate.Source = "SELECT * FROM tblstate"
rsstate.CursorType = 0
rsstate.CursorLocation = 2
rsstate.LockType = 1
rsstate.Open()

rsstate_numRows = 0
%>
<%
Dim rssecret
Dim rssecret_numRows

Set rssecret = Server.CreateObject("ADODB.Recordset")
rssecret.ActiveConnection = MM_FIT_STRING
rssecret.Source = "SELECT * FROM tblsecret"
rssecret.CursorType = 0
rssecret.CursorLocation = 2
rssecret.LockType = 1
rssecret.Open()

rssecret_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
alert(msg);
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors=',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == ');
}
//-->
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>

<body>
<form action="<%=MM_editAction%>" method="POST" name="frmreg" id="frmreg" onSubmit="MM_validateForm('cause',','R','first',','R','mi',','R','last',
','R','address',','R','city',','R','zip',','RisNum','sslast',',
'RisNum','hphone',','R','wphone',','R','login',','R','answer',','R',
'sfirst',','R','smi',','R','slast',','R','password',','R');return document.MM_returnValue">
<table width="476" border="1" align="center">
<tr bgcolor="#00CCFF">
<td colspan="2"><div align="center"><strong>Please Fill Out All Necessary Fields and Click Submit </strong></div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Cause Number </div></td>
<td><p>
<input name="cause" type="text" id="cause" size="16" maxlength="16">
<span class="style1">(No Dashes) </span><a href="javascript:;" onClick="MM_popupMsg('Located at the top right of any court document.\rExample:(41D020504DR00023)')"><img src="images/question.jpg" width="18" height="19" border="0"></a></p> </td>
</tr>
<tr>
<td width="241"><div align="right"><span class="style1">*</span>First Name </div></td>
<td width="219">
<div align="left">
<input name="first" type="text" id="first">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Middle Initial</div></td>
<td>
<div align="left">
<input name="mi" type="text" id="mi">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Last Name </div></td>
<td>
<div align="left">
<input name="last" type="text" id="last">
</div></td>
</tr>
<tr>
<td><div align="right">Email </div></td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Address</div></td>
<td>
<div align="left">
<input name="address" type="text" id="address">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>City</div></td>
<td>
<div align="left">
<input name="city" type="text" id="city">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>State</div></td>
<td>
<div align="left">
<select name="state" id="state">
<%
While (NOT rsstate.EOF)
%>
<option value="<%=(rsstate.Fields.Item("State").Value)%>"><%=
(rsstate.Fields.Item("State").Value)%></option>
<%
rsstate.MoveNext()
Wend
If (rsstate.CursorType > 0) Then
rsstate.MoveFirst
Else
rsstate.Requery
End If
%>
</select>
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Zip</div></td>
<td>
<div align="left">
<input name="zip" type="text" id="zip">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Last 4 of your SSN </div></td>
<td>
<div align="left">
<input name="sslast" type="text" id="sslast">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Home Phone </div></td>
<td>
<div align="left">
<input name="hphone" type="text" id="hphone">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Work Phone </div></td>
<td>
<div align="left">
<input name="wphone" type="text" id="wphone">
</div></td>
</tr>
<tr>
<td><div align="right">Work Ext </div></td>
<td>
<div align="left">
<input name="wext" type="text" id="wext">
</div></td>
</tr>
<tr>
<td><div align="right">On TANF or Permanent Disability?</div></td>
<td><div align="left">
<input name="tanf" type="checkbox" id="tanf" value="checkbox">
</div></td>
</tr>
<tr>
<td><div align="right">List any Special Requirements</div></td>
<td><div align="left">
<textarea name="specialmem" cols="25" rows="5" id="specialmem"></textarea>
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Login</div></td>
<td>
<div align="left">
<input name="login" type="text" id="login">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Password</div></td>
<td>
<div align="left">
<input name="password" type="password" id="password">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Choose a Secret Question</div></td>
<td><div align="left">
<select name="select">
<%
While (NOT rssecret.EOF)
%>
<option value="<%=(rssecret.Fields.Item("secretquest").Value)%>"><%=
(rssecret.Fields.Item("secretquest").Value)%></option>
<%
rssecret.MoveNext()
Wend
If (rssecret.CursorType > 0) Then
rssecret.MoveFirst
Else
rssecret.Requery
End If
%>
</select>
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Answer</div></td>
<td>
<div align="left">
<input name="answer" type="text" id="answer">
</div></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr bgcolor="#00CCFF">
<td colspan="2"><div align="center">Spouse Information </div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>First Name </div></td>
<td><div align="left">
<input name="sfirst" type="text" id="sfirst">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Middle Initial</div></td>
<td><div align="left">
<input name="smi" type="text" id="smi">
</div></td>
</tr>
<tr>
<td><div align="right"><span class="style1">*</span>Last Name </div></td>
<td><div align="left">
<input name="slast" type="text" id="slast">
</div></td>
</tr>
<tr bgcolor="#00CCFF">
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2"><div align="center"><span class="style1">*Required Fields </span></div></td>
</tr>
</table>

<input type="hidden" name="MM_insert" value="frmreg">
</form>
</body>
</html>
<%
rsstate.Close()
Set rsstate = Nothing
%>
<%
rssecret.Close()
Set rssecret = Nothing
%>


Christopher Abney
There is no limit to the good you can do if you dont care who gets the credit
 
Before adding the new record...you need to do a select query on your table to see if its a duplicate...

then you need to do something like this...

If rs.EOF AND rs.BOF THEN

'it is not duplicate and add the new user

Else

Response.Write("This user already exists")

End if

Please show us your code to get more help

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top