Computing.Net > Forums > Programming > error trap on P Key duplicate vb6

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

error trap on P Key duplicate vb6

Reply to Message Icon

Name: Anthony Arde
Date: May 16, 2005 at 03:19:09 Pacific
OS: winxp pro sp2
CPU/Ram: 386mb ram p3 733
Comment:

i get an error that bombs my program out when ever a duplicate value is entered in my DB program, please can someone tell me how to trap this error and let the user know what happened, thanks ant



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: May 16, 2005 at 04:25:04 Pacific
Reply:

at the beginning of the module put:


On Error Goto Duplicate:

Your stuff here

ExitSub:

Exit Sub

Duplicate:
if err = 3022 then
MssBox"Duplicate Record",vbOK
end if
Resume ExitSub:

You need to single step through the code and discover exactly which error is being generated and then allow for it. Error 3022 applies to DAO but may not apply if you are using ADO or MySQl.

ExitSub: and Duplicate: are just labels and can be anything you want. Notice the trailing colon.

Of course the other solution is to configure your database so it accepts duplicate records but they may or may not be what you want.

Stuart


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: error trap on P Key duplicate vb6

VB6 and database access question www.computing.net/answers/programming/vb6-and-database-access-question/925.html

Beginners help Pascal www.computing.net/answers/programming/beginners-help-pascal/6010.html

Error checking on a C area porgram www.computing.net/answers/programming/error-checking-on-a-c-area-porgram/11386.html