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

Error Trapping and Responding to an Access Msg. 1

Status
Not open for further replies.

VoodooRage

Programmer
Oct 9, 2002
43
US
I am working on an error handler in an Access 2000 function. I am fully capable of creating error handlers in private subs but I am having trouble with this error handler in a module function. When you are using the "OnError" sub on say a form you can identify the error, and use the Response = acDataErrContinue code to ignore an Access generated message.

How can I do this in a function where the err.description is displayed apparently prior to entering the error handler, the err.number is 2501.

Thanks bunches!
 
VR,

Len Reay in another thread in Tek-Tips gave the following. You should really look up the prob's first. I found this one on Google with ACCESS error 2501

the fix is:

Exit_Click:
Exit Sub
Error_Trap:
If err.Number = 2501 then
resume next
Else
..blah..
End If

rollie@bwsys.net

 
What I want to do is not have the default Microsoft Access error message (err.description) display. I would like to generate my own error message. When working in a sub routine for an event and error trapping say using the forms "OnError" event this is easy. I am writing a function that resides in a module and the code "Response = acDataErrContinue" is not working. It does not cause the code not to compile but it does not intercept the default error message either?

Thanks
 
Perhaps you could post your error handling code.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Code is as follows:

function test()
on error goto trap
code
code
code
exit funtion
trap:

'''the default access err.description pops up here prior to
'''hitting the "if" statement?

if err.number = 2501 then
msgbox(myerrormessage)
endif
 
The error is that the append query that I am running in VB cannot run, hence the 2501 error (RunSQL command stopped). the message I want to stop is associated with err.number 10510 and does not invoke the error handler?

Thanks
 
look at Help for turning off the warnings. Be sure and turn them back on afterwards tho.

rollie@bwsys.net
 
Actually the options are set not to notify when runnig an action query. The message err.description appears because the append query is trying to append records that are already in the table (key violation). The records cannot be added beacase they would cause vioations in the primary key for the table. That is why the message appears. Still the err.number does not allow this to be intercepted???
 
Maybe you could change your VBA error handling setting. In Tools->Options and the General Tab there are some error handling options. You might try setting it to Break on Unhandled Errors.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
How are you executing the Sql?
If you are using ‘DoCmd.RunSQL Sql’
Change it to ‘db.Execute Sql, dbFailOnError’
Any error will be passed to your error handler.
 
Thanks to everyone for helping me with this. This forum is great and StarPassing get warm fuzzies and a well deserved "YOU ROCK"!

Problem solved!

Thanks all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top