?
Solved

Microsoft Access - determine the name of the module which code is running in.

Posted on 2016-11-16
11
Medium Priority
?
102 Views
Last Modified: 2016-11-21
I'm having a brain cramp this afternoon.

I need to capture the name of the current code module, programmatically.

I know there is a function or some such which will return this value, but it just escapes me this afternoon.

Dale
0
Comment
Question by:Dale Fye
[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
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 58
ID: 41890449
<<I'm having a brain cramp this afternoon.>>

 No, your not.  There's no built-in function to do this.

 Best you can do is a Constant in each module.

Jim.
0
 
LVL 58
ID: 41890452
and maybe to clear up some confusion, vbWatchDog from Wayne Phillips will return a module name, but he hooked into VBA outside of Access and VBA itself.

Jim.
0
 
LVL 9

Assisted Solution

by:Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP) earned 700 total points
ID: 41890459
The Application.CodeContextObject.Name can return the name of the form or report that called the code. This is regardless of whether the code being executed is actually in a module.
E.g. button on form "frmTest" calls procedure fTest in module mTest:
Public Sub fTest()
    MsgBox CodeContextObject.Name
End Sub

Open in new window

This returns "frmTest"

Not exactly what you asked for, but I believe that is the best that can be done.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 48

Author Comment

by:Dale Fye
ID: 41890461
Jim,

I distinctly remember a discussion of this in the MVP google group, and I remember someone there mentioning it.  I even tested it, and it worked, I just for the life of me cannot even come up with a search term for the group email that might result in the discussion.  I'll wait a while here and if no one comes up with it, I'll check the google group.

Dale
0
 
LVL 58
ID: 41890463
<<and I remember someone there mentioning it. >>

 That would be news to me....

you can come up with the line number with vba.erl (undocumented), but not the routine or module name.

Jim.
0
 
LVL 48

Author Comment

by:Dale Fye
ID: 41890619
Well it turns out that the Application.CodeContextObject will return the name of the object that called the code, but will not return the name of the procedure that is actually running. And if you simply create a procedure which you want to display the CodeContextObject.Name, and you call that from the immediate window, you will get an error message.

 So I guess I'm going to have to go with setting a variable for each module name.
0
 
LVL 18

Expert Comment

by:John Tsioumpris
ID: 41891302
Does this does the job ?
Application.VBE.ActiveCodePane.CodeModule.Name

Open in new window

0
 
LVL 9

Expert Comment

by:Anders Ebro (Microsoft MVP)
ID: 41891308
Nope: That will show what the code EDITOR has active. Not what module the code is run from.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1300 total points
ID: 41891316
<< So I guess I'm going to have to go with setting a variable for each module name.>>

 That's what I do.   Each module has a const called ModuleName:

Const ModuleName = "Application Specific"

Open in new window


 and then each procedure has a const for RoutineName, along with a Version:

Public Sub AppMain()

          ' Mainline for processing of orders.

          ' 2.2.0.0 - OCS/JRD - 04/26/14 - Added check for orders that needed to be auto scheduled.
          ' 2.3.0.0 - OCS/JRD - 12/10/14 - Added call to get FedEx ship data and adjusted percentages.
          ' 2.4.0.0 - OCS/JRD - 03/18/15 - Added call to check for routing requests, get any routing instructions returned (EDI 754), and adjusted percentages.

          Const RoutineName = "AppMain"
          Const Version = "2.4.0.0"

Open in new window


and then an error handler that uses it all:

AppMain_Error:
1150      UnexpectedError ModuleName, RoutineName, Version, Err.Number, Err.Description, Err.Source, VBA.Erl
1160      Resume AppMain_Exit

Open in new window


and note the above was not for those here, but for anyone that might read this in the future and not have a clear understanding of what we are discussing.

Jim.
0
 
LVL 48

Author Closing Comment

by:Dale Fye
ID: 41896728
Thanks guys, combination of the two will meet my needs.
1

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

649 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