Suppress error message, close on run time error

M

mkb137

Is there any way to, on any untrapped error such as a run time error,
suppress the usual message dialog and instead close the application
immediately?

I have an application being launched on a server and would rather have it
fail on error than hang with an open dialog.

Thanks.
 
C

Chris O'C via AccessMonster.com

This should be obvious, but untrapped errors means the database development
isn't complete. Go back and finish the job.

If it's an unattended server app, you could use error handling like this:

public function functionname(arg1 as string) as string
on error go to proc_err

'buggy code goes here

proc_exit:
'clean up anything left undone
'close objects and set them to nothing
functionname = "whatever"
exit function

proc_err:
if err.number = 2501 then 'user cancelled
err.clear
resume proc_exit
else
currentdb.execute "insert into errorlog " _
& "(errno, errmsg, procname, errtime) " _
& "values (" & err.number & ", '" & err.description _
& "', '" & procedurename & "', #" & now() & "#)", _
dbfailonerror
err.clear
end if
end function


Chris
Microsoft MVP
 
C

Chris O'C via AccessMonster.com

Sorry, I forgot the "close the db" part:

proc_err:
if err.number = 2501 then 'user cancelled
err.clear
resume proc_exit
else
currentdb.execute "insert into errorlog " _
& "(errno, errmsg, procname, errtime) " _
& "values (" & err.number & ", '" & err.description _
& "', '" & procedurename & "', #" & now() & "#)", _
dbfailonerror
err.clear
docmd.quit
end if
end function
 
M

mkb137

Will all errors result in the "on error" function being called? I thought
some were untrappable.
 
C

Chris O'C via AccessMonster.com

Fatal errors are untrappable. If you've got those your code isn't going to
avoid the problem by quitting the app because your code won't be running at
that point. The developer has to figure out what's causing the fatal error.
First thing to try is compact/repair (back up first) to see if that fixes the
problem. It will if it's minor corruption but if it's major corruption or a
design flaw, compact/repair isn't enough.

Chris
Microsoft MVP
 
J

Jim Burke in Novi

It sounds like what you want is a 'global' error trapper that will catch any
error that isn't handled by an on error statement. While it's true that you
should capture all possible errors, this IS the real world. There's no simple
way to do that as far as I know, but there is some software out there that
will do that. Check out this link:

http://www.everythingaccess.com/simplyvba-global-error-handler.htm

NOt sure if it's exactly what you want, and there is a free version as well
as a purchased one - I've never looked ito it other than to check it out on
that site. Alex Dybenko, who's a regualr contributor here, posted about it a
while back. He links to it thru his site at http://accessblog.net/
 

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

Top