dbTalk Databases Forums  

access2007, how to show line of code that caused an error

comp.databases.ms-access comp.databases.ms-access


Discuss access2007, how to show line of code that caused an error in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roger
 
Posts: n/a

Default access2007, how to show line of code that caused an error - 12-10-2010 , 07:42 AM






if I have an error handler like this

on error goto fErr
....
....

fExit:
exit sub

fErr:
msgbox err.description
resume fExit

is there a way for the msgbox to also display either the line # or the
actual vba of the line that caused the error

note, the above msgbox is for illustration purposes, the actual error
handler logs the error to a text file, that's why logging the line #
or a reference to it would be helpful

Reply With Quote
  #2  
Old   
Bob Barrows
 
Posts: n/a

Default Re: access2007, how to show line of code that caused an error - 12-10-2010 , 08:32 AM






Roger wrote:
Quote:
if I have an error handler like this

on error goto fErr
fExit:
exit sub

fErr:
msgbox err.description
resume fExit

is there a way for the msgbox to also display either the line # or the
actual vba of the line that caused the error

There is a property in VB called Erl (I'm not sure this property exists
in VBA - it's been a while) that shows the line number of the line that
raised the error, but only if you use line numbers:
http://msdn.microsoft.com/en-us/libr...w1(VS.80).aspx.

Otherwise, the best you can do is check for an error after each line of
code using "on error resume next" instead of "on error goto
err_handler". This will allow you to return a different message box
title
for each line of code, allowing you to identify the guilty line:

on error resume next
blah blah blah
if err<>0 then
msgbox err.description,,"first statement"
exit sub
end if

blah blah blah2
if err<>0 then
msgbox err.description,,"2nd statement"
exit sub
end if



That's a lot of trouble to go through. For debugging, I will often use
something like this:
fExit:
exit sub

fErr:
msgbox err.description
Stop: Resume
resume fExit

commenting out the line when I am finished debugging. Resume, of course,
causes the same line that raised the error to be executed again.
--
HTH,
Bob Barrows

Reply With Quote
  #3  
Old   
Bob Barrows
 
Posts: n/a

Default Re: access2007, how to show line of code that caused an error - 12-10-2010 , 08:38 AM



Roger wrote:
Quote:
if I have an error handler like this

on error goto fErr
...
...

fExit:
exit sub

fErr:
msgbox err.description
resume fExit

is there a way for the msgbox to also display either the line # or the
actual vba of the line that caused the error

note, the above msgbox is for illustration purposes, the actual error
handler logs the error to a text file, that's why logging the line #
or a reference to it would be helpful
Oh, and check out this thread that I found when searching for "vba erl
property" after posting my previous reply (I was curious to see if it
existed in VBA):
http://stackoverflow.com/questions/3...error-handling

I wish I had known about MZ-Tools back when I was doing Access
development full-time.

--
HTH,
Bob Barrows

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.