Finding the current form programatically

R

Roland

Help Please! I'm running Access Ver 11

I know that to find the current user, I could use the function CurrentUser.
Now, how do I find the current form?

Thanks in advance.
Roland
 
A

Allen Browne

If you mean the form that contains the code that is running, try:
Me.Name

If you mean the form that currently has focus, try:
Screen.ActiveForm.Name

If you have multiple instances of the same form running, then just knowing
the name is not enough. More info in:
Managing Multiple Instances of a Form
at:
http://members.iinet.net.au/~allenbrowne/ser-35.html
 
R

Roland

Thanks for trying to help Allen, but it did not answer the question. My
codes are in a module which is not attached to a particular form. I'll be
calling functions from the module using the OnCurrent event on th forms.
Me.Name was not recognized in the module. I also tried the
Screen.ActiveForm.Name, but it gave an error message that the form must be
active. Any more suggestions please, to identify the current form, for I
need to set some properties programatically before the form displays.

Roland
 
A

Allen Browne

Pass a form reference to the function.

Declare the function in the standard module like this:
Public Function MyFunc(frm As Form)

You can then pass the form reference to the function by calling it like
this:
Call MyFunc(Me)
 
D

Dirk Goldgar

Roland said:
I also tried
the Screen.ActiveForm.Name, but it gave an error message that the
form must be active.

That may just be a result of the way you're testing your code. If in
practice the form would actually be active at the time the code runs,
Screen.ActiveForm could still work for you. Or, of course, you could
pass a reference to the form, as Allen suggested in his reply.
 
R

Roland

Thanks for the ideas Allen and Dirk. I set up a global variable in the
module and passed the current form using "Me" from the OnCurrent form event.

Thanks so much for the help.

Roland
 
Top