Author |
Message |
Russel Losk #1 / 20
|
 Finding current line number in Access 97 module
When editing a module, I would like for some VBA code to know which line I am presently editing. Using this information, I can use a module object to identify which procedure I am editing, what the first line of that procedure is, and where the procedure ends. I have written a macro that fills in the On error line and puts the exit and error handling code into the procedure that is currently open. I would like to write this routine entirely using code (with perhaps the exception being an initial call from an AutoKeys macro). Presently I have to use a macro that cuts and pastes as well as sends keys to the currently open module. To do run this from code, I need to know where I am in the module I am. Is there a VBA code or API call that will give me the information that I need? Knowing the Module name I can identify the module in the Modules collection. Knowing the Line number, I can identify the procedure and from that where the end of the procedure is. Can anyone help me with this? Russ Loski
|
Fri, 13 Oct 2000 03:00:00 GMT |
|
 |
Ken Ge #2 / 20
|
 Finding current line number in Access 97 module
Quote: > To do run this from code, I need to know where I am in the module I am. > Is there a VBA code or API call that will give me the information that I > need? Knowing the Module name I can identify the module in the Modules > collection. Knowing the Line number, I can identify the procedure and > from that where the end of the procedure is.
Access 97 provides relatively decent programmatic control over modules. It's certainly FAR from perfect (in other words, it's kinda ugly), but it does get you a lot of information. OTOH, I sure can't find a way to get the current line number. If you could find that, you could find out what procedure you were in, and go from there. Funny, I'm right smack in the middle of writing an error-handler add-in for VB (and later for Office) that does this same thing, but VB5's extensibility adds features to Access' (like, they provide a GetSelection method so you can find out what line you're on). If anyone reading this knows how to programmatically determine what code line is selected in Access, I'd like to hear about it, too! -- Ken
|
Sat, 14 Oct 2000 03:00:00 GMT |
|
 |
Dev Ashis #3 / 20
|
 Finding current line number in Access 97 module
Hi Russel, The closest I've ever come to this is to get the name of the form/report (under Access 97) the error occurs in. For example, paste this code behind a button '********** Code Start ********** Private Sub SomeButton_Click() On Error Resume Next Err.Raise vbObjectError + 10000 MsgBox "Error occurred in object: " & fCurrentObj Err.Clear End Sub '********** Code End ********** And this function in a new module '********** Code Start ********** Function fCurrentObj() As String Dim objCurrent As Object On Error Resume Next Set objCurrent = CodeContextObject fCurrentObj = objCurrent.Name If Err Then Err.Clear End Function '********** Code End ********** Now, if you click the button, you should get the nameof the form this button is in. That said and although Access 97 Help mentions the fact that CodeContextObject is property of the Application object, I haven't been able to get it to work purely in a module alone. Also, if your form calls a function which in turns calls this fCurrentObj function, then regardless of where you're raising the error, you'll get the ActiveForm.Name. Now on the module side, you do have the new Lines method which allows you (along with Find method) to search for a line by text and return it via a function. But again, no help on which line the code was when the error happened. After playing with the Lines and Find methods, I basically gave up on it <g>. I mean surely none of us are expected to guess which lines the errors might occur on and hard code a string on it during development. Hope I didn't miss anything. I think I can speak for other ng regulars that a ErrOnLine property or something is sorely needed. (hmmm... Is it my ISP that's showing only this message after this morning?? Even though your message is from yesterday!) Dev -- Dev Ashish (Just my $.001) --------------- The Access Web ( http://home.att.net/~dashish ) --------------- Quote:
>When editing a module, I would like for some VBA code to know which line >I am presently editing. Using this information, I can use a module >object to identify which procedure I am editing, what the first line of >that procedure is, and where the procedure ends. >I have written a macro that fills in the On error line and puts the exit >and error handling code into the procedure that is currently open. I >would like to write this routine entirely using code (with perhaps the >exception being an initial call from an AutoKeys macro). Presently I >have to use a macro that cuts and pastes as well as sends keys to the >currently open module. >To do run this from code, I need to know where I am in the module I am. >Is there a VBA code or API call that will give me the information that I >need? Knowing the Module name I can identify the module in the Modules >collection. Knowing the Line number, I can identify the procedure and >from that where the end of the procedure is. >Can anyone help me with this? >Russ Loski
|
Sat, 14 Oct 2000 03:00:00 GMT |
|
 |
Andy Bar #4 / 20
|
 Finding current line number in Access 97 module
Quote: > I think I can speak for other ng regulars >that a ErrOnLine property or something is sorely needed.
And the most frustrating part is that we used to have it! From Access 2.0 Help: "After an error occurs, the Err function returns an Integer run-time error code identifying the error. The Erl function returns an Integer that is the line number of the line in which the error occurred or the line most closely preceding it." -- Andy
|
Sun, 15 Oct 2000 03:00:00 GMT |
|
 |
Ken Ge #5 / 20
|
 Finding current line number in Access 97 module
Quote: > "After an error occurs, the Err function returns an Integer run-time > error code identifying the error. The Erl function returns an Integer > that is the line number of the line in which the error occurred or the > line most closely preceding it."
But that only worked if you MANUALLY added line numbers, if I'm not mistaken. That is, it never told you the physical line number unless the line was numbered. And this still works in Access 97, as far as I know. To make use of ERL in any version, I think you had to go through and add line numbers to your code. Yikes! Back to 1983! -- Ken
|
Sun, 15 Oct 2000 03:00:00 GMT |
|
 |
Andy Bar #6 / 20
|
 Finding current line number in Access 97 module
I didn't realize that erl was still supported. I didn't see it in Help or in the Object Browser and thought I remembered some complaints about it being gone, so I assumed it was gone. But I tested it and indeed it works fine. This won't help the originator of this thread who is looking for a line number at design-time. But it could be very valuable in error tracking. Not every line needs a line number -- just those you want to track. The first line of a section can be numbered, and that number will be returned even if the error occurs on a subsequent un-numbered line. And if full granularity is desired, the numbering could be automated anyway, right? I can see where erl could be used to good effect, and we never talk about it. hmm...I smell a SmartAccess answer <g>. -- Andy Quote:
>> "After an error occurs, the Err function returns an Integer run-time >> error code identifying the error. The Erl function returns an Integer >> that is the line number of the line in which the error occurred or the >> line most closely preceding it." >But that only worked if you MANUALLY added line numbers, if I'm not >mistaken. That is, it never told you the physical line number unless the >line was numbered. And this still works in Access 97, as far as I know. >To make use of ERL in any version, I think you had to go through and add >line numbers to your code. Yikes! Back to 1983! -- Ken
|
Sun, 15 Oct 2000 03:00:00 GMT |
|
 |
Ken Ge #7 / 20
|
 Finding current line number in Access 97 module
Quote: > I can see > where erl could be used to good effect, and we never talk about it. > hmm...I smell a SmartAccess answer <g>.
Well, I have to write a column for them next month, so perhaps we'll see it in the September column? <g> Thanks for the suggestion. -- Ken
|
Sun, 15 Oct 2000 03:00:00 GMT |
|
 |
Ken Ge #8 / 20
|
 Finding current line number in Access 97 module
Quote: > ERL may be still lurking around within the 2.5/3.0 campatablity layer...
Nope, that's only DAO stuff. ERL isn't, and never was, part of DAO -- it's provided by the VBA language engine. No, it's still there, has always been there, and probably always WILL be there (the old saying is that you add features FOR LIFE to software. Once it's in there, and people use it, you really can't remove it.) -- Ken
|
Sun, 15 Oct 2000 03:00:00 GMT |
|
 |
John Dougla #9 / 20
|
 Finding current line number in Access 97 module
ERL may be still lurking around within the 2.5/3.0 campatablity layer... Quote:
> > I can see > > where erl could be used to good effect, and we never talk about it. > > hmm...I smell a SmartAccess answer <g>. > Well, I have to write a column for them next month, so perhaps we'll see > it in the September column? <g> Thanks for the suggestion. -- Ken
--
(To reply: please remove nSoPAM. from reply address - Thanks)
|
Mon, 16 Oct 2000 03:00:00 GMT |
|
 |
Andy Bar #10 / 20
|
 Finding current line number in Access 97 module
I meant that _I_ might use it for one that I have coming up. I'll flip a coin and tell you the results.<g> -- Andy Quote:
>> I can see >> where erl could be used to good effect, and we never talk about it. >> hmm...I smell a SmartAccess answer <g>. >Well, I have to write a column for them next month, so perhaps we'll see >it in the September column? <g> Thanks for the suggestion. -- Ken
|
Mon, 16 Oct 2000 03:00:00 GMT |
|
 |
Ken Ge #11 / 20
|
 Finding current line number in Access 97 module
Quote: > I meant that _I_ might use it for one that I have coming up. I'll flip > a coin and tell you the results.<g>
Go for it. I've got a few weeks before I have to do mine, and I'm sure other issues will come up. -- Ken
|
Mon, 16 Oct 2000 03:00:00 GMT |
|
 |
Bill Musgrav #12 / 20
|
 Finding current line number in Access 97 module
Here is an idea. How about documenting the /decompile switch in Jet 3.51! Bill Quote:
>> I meant that _I_ might use it for one that I have coming up. I'll flip >> a coin and tell you the results.<g> >Go for it. I've got a few weeks before I have to do mine, and I'm sure >other issues will come up. -- Ken
|
Mon, 16 Oct 2000 03:00:00 GMT |
|
 |
Andy Bar #13 / 20
|
 Finding current line number in Access 97 module
Good idea! I first heard about that from Dan Haught at FMS, and it has gotten me out of a couple of jams. I looked, and still don't see a knowledgebase article on it. For those eavesdropping, the /decompile command line switch can be used when opening an Access database (usually from Run on the Start menu or from a shortcut). This allows you to completely recompile the VBA project from the source code, which can solve some otherwise intractable VBA problems. -- Andy Quote:
>Here is an idea. How about documenting the /decompile switch in Jet 3.51! >Bill
>>> I meant that _I_ might use it for one that I have coming up. I'll flip >>> a coin and tell you the results.<g> >>Go for it. I've got a few weeks before I have to do mine, and I'm sure >>other issues will come up. -- Ken
|
Mon, 16 Oct 2000 03:00:00 GMT |
|
 |
Dev Ashis #14 / 20
|
 Finding current line number in Access 97 module
Quote:
>Good idea! I first heard about that from Dan Haught at FMS, and it has >gotten me out of a couple of jams. I looked, and still don't see a >knowledgebase article on it. >For those eavesdropping, the /decompile command line switch can be >used when opening an Access database (usually from Run on the Start >menu or from a shortcut). This allows you to completely recompile the >VBA project from the source code, which can solve some otherwise >intractable VBA problems. > -- Andy
>>Here is an idea. How about documenting the /decompile switch in Jet 3.51!
Heh heh!! learnt about that from Michael Kaplan myself. Have not used it myself yet, but since I added that article to my website, received several emails saying it works!! Thanks Michael and Andy. Dev --
|
Mon, 16 Oct 2000 03:00:00 GMT |
|
 |
Michael Kapla #15 / 20
|
 Finding current line number in Access 97 module
Not sure why on earth it would be doc'ed for Jet 3.51, since it has nothing to do with Jet at all.... Michael
Quote:
>>Good idea! I first heard about that from Dan Haught at FMS, and it has >>gotten me out of a couple of jams. I looked, and still don't see a >>knowledgebase article on it. >>For those eavesdropping, the /decompile command line switch can be >>used when opening an Access database (usually from Run on the Start >>menu or from a shortcut). This allows you to completely recompile the >>VBA project from the source code, which can solve some otherwise >>intractable VBA problems. >> -- Andy
>>>Here is an idea. How about documenting the /decompile switch in Jet 3.51! >Heh heh!! learnt about that from Michael Kaplan myself. Have not used it >myself yet, but since I added that article to my website, received several >emails saying it works!! >Thanks Michael and Andy. >Dev >--
|
Tue, 17 Oct 2000 03:00:00 GMT |
|
|