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

Trapping Errors

Status
Not open for further replies.

Ouch

Programmer
Jul 17, 2001
159
GB
Hope someone can help me.

I have a page and if a users attempts to add a user that aready exsist it returns this error, which is good.

i want to trap this error so i can put a message saying 'the user allready exsists'

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.

/webct/users/Externals/request.asp, line 35

i am quite new to asp.

thanks

 
Rather that wait for the error message do a SELECT query to see if the user already exist before doing an INSERT.
 
how?

somtihing like

do while not rs.eof

if request.form(name) = rs("name") The response.write "This user allready exsists"

next

rs.movenext
loop

how do i get it to stop running the loop if the if statement is true
 
I usually assign my recordsets to an array using getrows()
so i would have said
arrUsers = rs.getRows '(this lets you have just the row data, not the rest of the guff found in a recordser)
...
for i = lbound(arrUsers,2) to ubound(arrUsers,2)
if request.form(name) = arrUsers(1,i) Then
response.write "This user allready exsists"
exit for
end if
next


arrUsers(1,i) would be the position in the array where the user name is kept, so you would obviously change that ot the correct index position for the name
 
thanks for your help, this is how i did it

Code----

exsists = false

do while not rsChk.eof
if email = rsChk("email") Then
exsists = true
end if
rsChk.movenext
loop

if exsists = false then
'do the inserts stuff
else

response.write" users already exsists"

end if
 
another neat way, I just like breaking out of the loop as soon as i have found what im looking for, just in case there are 2million records and the name im looking for is the first one in the list.

Could you not modify your do statement to say:

do while (not rsChk.eof) and exsist = false

might work, not sure
 
Alternatively, just put an 'exit do' statement after 'exsists = true'.

HTH
Beck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top