Hi Mark,
There is an "undocumented" function: Erl()
that will return an offending line number (provided your code uses line
numbering)
.... I know what you're thinking ... "You mean I have to go back through ALL
of my code and insert line numbers!!!???" <Roll eyes>
Well ... "Yes and No." <grin>
Have a look at this link to a "Code Comment Builder Wizard" that you CAN use
to automatically generate line numbers.
http://www.mvps.org/access/modules/mdl0031.htm
OK, OK ... I know ... we're going back to having our code look like it was
written in 1980 ... but it should work. <grin>
PS.
I also kind of fooled around with some of the Module properties ..."Lines",
"CountOfLines"
.... but I can't seem to find a way to "merge" both ideas.
It would be nice to be able to record the actual line of text as well as the
line number, right?
===================================
The majority of this is copied / pasted from Help (I just added the line
that prints whatever is on the 6th line of the selected module):
===================================
Option Compare Database
Option Explicit
Function ModuleLineTotal(strModuleName As String)
Dim mdl As Module
' Open module to include in Modules collection.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Print number of lines in module.
Debug.Print "Number of lines: ", mdl.CountOfLines
' Print number of declaration lines.
Debug.Print "Number of declaration lines: ", _
mdl.CountOfDeclarationLines
Debug.Print mdl.Lines(6, 1) 'Print whatever is on the 6th line of code
End Function
===================================
From the Debug Window to show usage and results:
===================================
ModuleLineTotal("modBrowseFolder")
Number of lines: 57
Number of declaration lines: 34
'This code was originally written by Terry Kreft.
(The "BrowseFolder" API can be found here:
http://www.mvps.org/access/api/api0002.htm)
if you want to see that the 6th line was indeed "'This code was originally
written by Terry Kreft."
--
--
HTH,
Don
=============================
E-Mail (if you must)
My*****@Telus.net
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)
I'm an Access97 user, so all posted code samples are also Access97- based
unless otherwise noted.
================================================== ========================
"Mark" <mr*******@btinternet.comwrote in message
news:ds******************************@bt.com...
Hi All,
I have wrote a sub to record events from within the database. A lot of
these events are errors. The sub has the module name and function/sub name
passed to it to record to the table. My problem is that a lot of the subs
within the modules are quite large so haveing the module name and
procedure name points me in the right direction but I would like to be
able to record which line of code has produced the error.
Is this possible?
TIA,
Mark