Identifying the subprocedure that called a function

PearlGI

Registered User.
Local time
Today, 11:26
Joined
Aug 30, 2001
Messages
125
How can you identify the name of the SubProcedure that called a Function.
Surely the function must know where it's return address is?

The problem I'm trying to solve is this:
I've set up a function which could be called from any number of SubProcedures, but I need to be able to detect which SubProcedure the call came from.

Can anybody help? Surely there's a solution!
 
There may be a slicker way, but either of these should work:
1. Make the first parameter of the function the name of the calling routine. Then, calling modules will have to pass their name in...

2. Declare a global variable. I usually put these in a module with a catchy name like "modGlobalVariables".
Global strCaller As String

Every module that calls your function will need to put its name into that variable:
strCaller = Me.Name
or
strCaller = "FizzBin" 'depends on what you need

..and you can then use strCaller in your function.
 
Both solutions you suggest have problems with the way I need them to work. I have a form with 100 input cells and when a cell is changed by a user, I need to be able to change other cells depending on what cell was changed by the user, hence needing to know the calling subprocedure.

Solution 1 is possible but extremely time consuming given the number of procedure involved.

Solution 2 (Me.Name) returns the name of the form rather than the name of the calling procedure.

Ideally I need solution that doesn't involve repeated keying of the procedure name.

Many thanks though.
 
I think I might have found something that may work, but I need some help with it. The property EventProcPrefix looks like it could work, but I'm not sure what object to apply it it.

I need some thing like this:

Sub Cell59_Change()
myFunction(EventProcPrefix)
End Sub

Function myFunction(strProc as String)
..
{code}
..
End Function

What object does the EventProcPrefix property need to relate to?
 
This worked for me.

Everytime a value was changed I needed to change other values on the form based on the value just entered. Thus I needed to be able to identify which control had just changed.

I used the LostFocus event on every control on a form to call a sub-procedure. This sub-procedure then identified the control and performed the manipulation of the other controls on the form.


This method returns the name of the control that called the sub-procedure:

Me.ActiveControl.EventProcPrefix

HTH
 
Yes, Screen.PreviousControl.Name would produce the same results.
(But nobody suggested that 18 months ago when I had the problem to solve :eek: )
 

Users who are viewing this thread

Back
Top Bottom