Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Line Numbers in VBA Code?

Posted on 2002-05-06
6
Medium Priority
?
1,848 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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