Help with a standard module to get current module name

  • Thread starter Cyberwolf0000 via AccessMonster.com
  • Start date
C

Cyberwolf0000 via AccessMonster.com

Hi all,

I have found this code on the MS website that loops through to give you the
module names of all the modules in a database. I would like to modify it to
just show the currently running module. I was going to convert to a function
and output the name.

Public Sub modName()

Dim modObj As Object
Dim strModule As String
Dim x As Integer

For x = 1 To Application.VBE.ActiveVBProject.VBComponents.Count
Set modObj = Application.VBE.ActiveVBProject.VBComponents.Item(x)
strModule = modObj.CodeModule.Name
Debug.Print strModule
Next x

End Sub

Any help would be greatly appreciated.

TIA,
 
S

Stuart McCall

Cyberwolf0000 via AccessMonster.com said:
Hi all,

I have found this code on the MS website that loops through to give you
the
module names of all the modules in a database. I would like to modify it
to
just show the currently running module. I was going to convert to a
function
and output the name.

Public Sub modName()

Dim modObj As Object
Dim strModule As String
Dim x As Integer

For x = 1 To Application.VBE.ActiveVBProject.VBComponents.Count
Set modObj = Application.VBE.ActiveVBProject.VBComponents.Item(x)
strModule = modObj.CodeModule.Name
Debug.Print strModule
Next x

End Sub

Any help would be greatly appreciated.

TIA,

There's no such thing as a "currently running module". There may, however,
be a currently running procedure in a standard module, but AFAIK it's almost
impossible to determine because Access doesn't expose it as a property.
 
C

Cyberwolf0000 via AccessMonster.com

Yes, that is what I meant a currently running procedure.

Thanks,

Stuart said:
[quoted text clipped - 23 lines]

There's no such thing as a "currently running module". There may, however,
be a currently running procedure in a standard module, but AFAIK it's almost
impossible to determine because Access doesn't expose it as a property.

--
James B Gaylord
For the Wolf comes the strength of the Pack,
For the Pack comes the strength of the Wolf,
-R. Kipling
Office 2003 on Win XP SP2
 
J

Jack Leach

http://www.fmsinc.com/

If you navigate your way to the access code examples and look under the
advanced error handling section, you will see an example of building a
procedure call stack array. AFIAK this (or a simlar method) is the only way
to do this.

Also, I use the MZTools addin, which allows you to insert the procedure
name/type etc into the code as part of an error handler or procedure header.
You could adapt this functionality to store the procedure in a variable at
the beginning of the procedure when adding error handling, etc, and use it as
part of your code from there.

hth


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



Cyberwolf0000 via AccessMonster.com said:
Yes, that is what I meant a currently running procedure.

Thanks,

Stuart said:
[quoted text clipped - 23 lines]

There's no such thing as a "currently running module". There may, however,
be a currently running procedure in a standard module, but AFAIK it's almost
impossible to determine because Access doesn't expose it as a property.

--
James B Gaylord
For the Wolf comes the strength of the Pack,
For the Pack comes the strength of the Wolf,
-R. Kipling
Office 2003 on Win XP SP2
 
S

Sky

Stuart McCall said:
There's no such thing as a "currently running module". There may, however,
be a currently running procedure in a standard module, but AFAIK it's
almost impossible to determine because Access doesn't expose it as a
property.

There is this tool:
http://www.everythingaccess.com/simplyvba-global-error-handler.htm

It provides the call stack and original line number, without requiring
additional code. It does require a DLL, however. The developer edition is
free, but costs money for distribution.

- Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top