Making Functions work like RunCommand

  • Thread starter Thread starter Bill Mitchell
  • Start date Start date
B

Bill Mitchell

RunCommands seem to work on the form that has the focus
no matter where it is (main form, sub form, etc...) How
can I get my Functions to work the same way without
specifying locations? It must be possible because
RunCommands do it. I want to use the fucntions in my
shortcut menus.

Does anyone know?
 
RunCommands seem to work on the form that has the focus
no matter where it is (main form, sub form, etc...) How
can I get my Functions to work the same way without
specifying locations? It must be possible because
RunCommands do it. I want to use the fucntions in my
shortcut menus.

Bill,

take a look to the ActiveForm, ActiveReport and ActiveControl
properties (see Help on these). They return the form /report /control
having the focus. Example for use:

Dim frmCurrent As Form
Set frmCurrent = Screen.ActiveForm

You might need a bit of testing for subforms though, just to make
sure.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Thanks,

However, Sceen.Activeform returns only the name of the
Parent Form. Honestly, I have NO CLUE as to why Access
does this. If my subform has the focus, it still returns
only the name of the Parent as my screen.activeform? Oh
yeah, that's helpful, lol.

Back to the drawing board.

There must be some other way to do this as RunCommands do
it.
 
Thanks,

However, Sceen.Activeform returns only the name of the
Parent Form. Honestly, I have NO CLUE as to why Access
does this. If my subform has the focus, it still returns
only the name of the Parent as my screen.activeform? Oh
yeah, that's helpful, lol.

Back to the drawing board.

Bill,

what are you trying to achieve then? For standard menu commands you
can create a custom menu bar, and operations related to subforms are
usually specific.

BTW, Access can of course dig deep in API, in the own C++ code etc.
Not everything is exposed to mere mortal developers like us.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Actually, you can use the runcommand directly in a meuu. However, since
those expression are interpreted at run time, then just like when you use a
expression in a sql statement, you can use the build in constants.

So, the solution is to use the debug window to "display" the constant value
you need.

So, open up the debug window, and type in:

? acCmdClose
58

You will see that the constant value is 58, so in your menu bar "on action"
you can use:

=RunCommand(58)

So, the above is the equivalent of:

docmd.RunCommand acCmdClose

or
docmd.RunCommand 58

Just remember, you can't use the built in constants in those expressions.
So, even in sql, you can't go:

? strconv("test",vbUpperCase)
TEST

? vbUpperCase
1

So, in sql expressions, you can use:

=strConv([LastName],1) as MyUppperName
 
Thanks Albert,

But that wasn't the point of my post. My question was,
how can I make my customzied functions "see" the location
of where my shortcut menu is being call just like
runcommands do?

As it is now, I have to write a different function for
each subform I use a shortcut menu on because the form
location naming has changed. I would like to just write
one function and be able to use it in a shortcut menu
anywhere without specifying:

With forms![Main]![Contact].form![MySubform1]

or

With forms![Main]![Contact].form![MySubform2]

etc... in my underlying function.

One solution I thought of was to actually set the
Shortcut Menu programatically when I enter the subform,
thereby specifying the location at that time using
something like MyShortcutFunction(frm as Form) to draw
the form name. However, I dont know how to specify the
underlying function to a shortcut menu using code :(

I want to function to act on any form the shortcut menu
is used on just as if I were using the Me! statement.
This is a problem as my shortcut menu doesnt seem to know
where it "is" even though it is designated as the
shortcut for the form it is on.

Does that make any sense?
 
With forms![Main]![Contact].form![MySubform1]

or

With forms![Main]![Contact].form![MySubform2]

etc... in my underlying function.

One solution I thought of was to actually set the
Shortcut Menu programatically when I enter the subform,
thereby specifying the location at that time using
something like MyShortcutFunction(frm as Form) to draw
the form name. However, I dont know how to specify the
underlying function to a shortcut menu using code :(

Bill,

I would like to ask again: what generic functions do you need others
than the standard menu commands which you can use in a custom menu bar
or shortcut menu bar?

If all forms have only one subform, you could check in a loop the
control type of all controls in ActiveForm and so find the subform
control. Then maybe check if that control has the focus. But again, to
what purpose? Maybe there is some other solution.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Back
Top