Trapping odbc error when exec'ing INSERT command

D

Doo-Dah Man

I hope this is the right group for this question, if it's not please
direct me.

I have a data-driven website that allows users to enter records for
sales leads. It all works perfectly. The only thing I want to do
right now is prohibit users from entering the same lead twice. I have
a PK field in the MS Access database that, obviously, disallows
duplicate records. However, when such an attempt is made, the browser
redirects to some generic ODBC error page with some cryptic numbers
and other information that will stymie the users. "It doesn't work",
they will say. The text of that error indicates that they tried to
add a record that violates the PK rule of disallowing duplicate
records. But they probably won't read it and it's truly ugly anyway.

How can I redirect to a custom error page or trap the error before the
ODBC error page is displayed and just display a msgbox or something
telling the user they attempted to add a record that already exists?

Thank you
 
A

Aaron [SQL Server MVP]

Sql = "..."
on error resume next
Conn.execute sql,,129
If err.number <> 0 then
Response.write "<script>alert('" & err.description & "');</script>"
Else
... Continue processing
End if

Also see http://www.aspfaq.com/2509
 
D

Doo-Dah Man

Wow! Thanks for the quick response. I will give this a try tomorrow.

And thanks also for the great link.




On Tue, 22 Mar 2005 01:02:47 -0500, "Aaron [SQL Server MVP]"
<[email protected]> stood up, looked around, realized where he
 
B

Bob Barrows [MVP]

Doo-Dah Man said:
I hope this is the right group for this question, if it's not please
direct me.
Please do not multipost Doo-Dah.This is definitely a database-related
question so .asp.db was the perfect group in which to post it. Posting it
here as well did not increase your chances of getting an answer (most of us
subscribe to both groups). On the contrary, if somebody had taken his time
to answer it here, only to find that it was already resolved in the other
group, that person may have been annoyed enough to ignore any future posts
from you, thereby decreasing your chances of getting help in the future.

There are times when you will not be sure which group is most appropriate
(again, this was not one of them), and you will want to post a question to
both groups. In that situation, you should use the cross-posting technique,
rather than posting the same message multiple times. To crosspost, put
a semicolon-delimited* list of the newsgroups to which you wish to post in
the To: header of your post and post it once. It, and any replies to it,
will appear in all the newsgroups in your list. So, if I reply in .asp.db,
my reply will also appear here in .asp.general.

* ... or whatever delimiter is recognized by your news client
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top