Solved

Line Numbers in VBA Code?

Posted on 2002-05-06
6
1,749 Views
Last Modified: 2012-06-27
I have a rather large VBA subroutine I wrote.  I am trying to split it up, but until then, there are a few areas that might encounter an error.  I'd like to know whereabouts in the module the error occurred.  

Mind you, this is distributed as an MDE, so the user cannot get to the code, even during an error.  Right now, I have it put up a screen, with the module name, and Access/Jet Error number. Is there a way to tell *where* in the module it happened?  (Of course, I can go back and devise where it occurred, based on ErrNo, but I'm lazy that way)....

Thanks in advance.
0
Comment
Question by:dougp23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Accepted Solution

by:
n f earned 50 total points
ID: 6991845
As far as I know, you can't get the line number to be returned, but you can get around this by creating a local variable at the beginning of your sub and then changing it at specific points in your code.  Change the variable to tell you what's going on in your code at that point.

For example:
Sub MySub()
On Error GoTo errTrap

Dim errHere as string

errHere = "top"
start your code...
....
errHere = "updating tblOne"
more code...
....
etc.

Then in the error trap,
errTrap:
   Msgbox "Error number " & err.number & vbCr & _
       "(" & Err.Description & ") occured at " & _
       errHere
   Exit Sub


The more times you change the variable, the more specific you can be in where the error is occuring.
         

0
 
LVL 58
ID: 6992153
Nothing outside of what was already metnioned as your using a MDE, which has no source code that can be read.  

Whatever labeling you do, you'll need to do it on your own.

Jim.
0
 
LVL 4

Expert Comment

by:srauda
ID: 6992353
Yep.  Use it all the time and it saves big time and headaches when debugging.

Try the following:

sub Test()

     dim x integer, y integer

05   on error goto Test_Err
10   x = 10
20   y = 0
30   msgbox x/y
40   exit sub

Test_Err:
    msgbox "Error: " & err.number & vbcrlf & "Description: " & err.description & vbcrlf & "Line: " & erl

end sub

Erl is an undocumented function in vb and vba.  If the function or sub has no line numbers, Erl returns 0.



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:srauda
ID: 6992357
For vb, there is a line number generator, but I have yet to find one for Access.  Was thinking of writing one for myself.
0
 
LVL 58
ID: 6992386
srauda,

<<For vb, there is a line number generator, but I have yet to find one for Access.  Was thinking of writing
one for myself. >>

  FMS, Inc. includes one as part of their Total Access Detective.

Jim.
0
 
LVL 1

Author Comment

by:dougp23
ID: 6994190
Thanks!  Even though I started out asking forline #s, I think this solution is cleaner.
As far as line # generator, the Access Developers Book (by Litwin, et. al.) has a nice line # generator (requires you to export the module to text first, then re-import it after it adds #s).

Like I said, though, I like nfeldman's idea.
Thank you all.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question