Highlighting a line during debugging

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

Normally, when a run-time error occurs, a dialogue box appears giving the
error number and description. A button called ‘Debug’ takes you to the code,
highlighting the line where the error occurred.

If you use error handling (On Error Goto….) you no longer get this dialogue
box. The Err object can provide the error number and description, but is
there still a way to highlight the line where the error occurred?

Many thanks

David
 
Hi, David.
The Err object can provide the error number and description, but is
there still a way to highlight the line where the error occurred?

It's an "either/or" situation. Either you get your own user-friendly error
handling, or you get the default error message dialog box with the option to
debug the code (i.e., jump to the offending line of code, which is
highlighted in the VB Editor).

You may change the VB Editor setting prior to running code that you think
may experience run-time errors, thereby enabling the default error messages
and will ignore all of your own error handling. To do so, open the VB Editor
and select the Tools -> Options... menu and then select the "General" tab.
Select the "Break on All Errors" option under the "Error Trapping" section,
then select the "OK" button to save your change.

All subsequent run-time errors will display the default error message and
the option to jump to the highlighted line of code which is causing the
error. When you are ready to use your own error handling again, open the VB
Editor and select the "Break On Unhandled Errors" option.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
Hi there

Thanks for this.

My problem is that I have some code which uses an error handler as a normal,
operational part of the code (see my thread above to see why). Thus, if I
disable the error handler, the code itself won't work.

I take it from your message that there is no way to get my error handler to
highlight the offending line...

Cheers

David
 
Hi, David.
I take it from your message that there is no way to get my error handler to
highlight the offending line...

The VB Editor isn't intended to be manipulated from VBA code with such fine
detail as you'd like to use. The VB code which highlights the source code
(as in "execution point text") is:

RunCommand acCmdShowNextStatement

However, if you try using this command in your VBA code in the current
project, you'll receive a run-time error that the command isn't available at
this time. The only other way I know of to highlight text in the code module
is to use a selection text method, but it doesn't work the same as the
execution point text that you expect to see when using the debugger in break
mode. You could use the following code example after setting a reference to
the VBIDE library:

Application.VBE.ActiveCodePane.SetSelection 100, 5, 100, 30

The caveat is that your code needs logic to determine which numbers to feed
this method for the starting/ending lines and columns. It's not very useful
in your situation, unless you want your code to keep track of line numbers.

The default path and file name for this library is:

C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
Back
Top