Setting Shortcut Menu Functions at runtime?

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

Bill Mitchell

Hi,

I use many Shortcut Menus on forms and subforms. My
Shortcut Menus are based upon Macros which call various
RunCommands and RunCodes. The Runcodes are based upon
Functions() I have written that are like:

Public Function MyShortcutMenu(GetType as String,frm as
Form)

With frm
Select Case GetType
Case "Requery"
.Requery
Case "Etc..."
end select
end with

end Function

When I call the shortcut menu, I want to be able to send
the Subform location to the Function at runtime. This
way the shortcut will work wherever I am, sort of like
Runcommands do.

Does anyone know how I can do this?

Sort of like this:

MyShortcutMenu(GetType,forms![Main]![Contact].form!
[MySubform1])

if MySubform1 has the focus, or

MyShortcutMenu(GetType,forms![Main]![Contact].form!
[MySubform2])

if MySubform2 has the focus.

Thanks, Bill
 
You don't need to pass the name of the form to your functions. Which ever
form you call the function from will still have the focus when the function
runs so just use Me to refer to the form instead of spelling out the name.

Public Function MyShortcutMenu(GetType as String)
Select Case GetType
Case "Requery"
Me.Requery
Case "Refresh"
Me.Refresh
Case "Etc..."
...
End Select
End Function

Kelvin
 
Thanks,

But have you tried this? It doesn't work with shortcut
menus. Give it a try and you will see. It "should" work
but it doesn't.

Bill
-----Original Message-----
You don't need to pass the name of the form to your functions. Which ever
form you call the function from will still have the focus when the function
runs so just use Me to refer to the form instead of spelling out the name.

Public Function MyShortcutMenu(GetType as String)
Select Case GetType
Case "Requery"
Me.Requery
Case "Refresh"
Me.Refresh
Case "Etc..."
...
End Select
End Function

Kelvin

Hi,

I use many Shortcut Menus on forms and subforms. My
Shortcut Menus are based upon Macros which call various
RunCommands and RunCodes. The Runcodes are based upon
Functions() I have written that are like:

Public Function MyShortcutMenu(GetType as String,frm as
Form)

With frm
Select Case GetType
Case "Requery"
.Requery
Case "Etc..."
end select
end with

end Function

When I call the shortcut menu, I want to be able to send
the Subform location to the Function at runtime. This
way the shortcut will work wherever I am, sort of like
Runcommands do.

Does anyone know how I can do this?

Sort of like this:

MyShortcutMenu(GetType,forms![Main]![Contact].form!
[MySubform1])

if MySubform1 has the focus, or

MyShortcutMenu(GetType,forms![Main]![Contact].form!
[MySubform2])

if MySubform2 has the focus.

Thanks, Bill


.
 
Any reason why you don't dump the use of macros?

They are really messy, and I see little reason to use them. Once you get
beyond the amateur stage of using ms-access, you will find using Macros of
little value. You might just have to dump the bicycle training wheels called
macros, and simply use code.

Why not just call the code function directly from the menus?

You get much more flexibility in this regards, and you can pick up the
active screen. I would suggest you get rid of the macros.

With code, you can pickup the screen and active control, even in the case of
a sub form, or a sub-sub form.

Also, do note that if you use functions in your shortcut menus, then you can
add parameters to those functions. So, for example, the on action of a menu
option might be:

=MyShortCutMenu("MyRequery","LastName","frmCustomer")


Your function is thus called directly by the on-action.

Public Function MyShortcutMenu(GetType as String,
strField as string, _
strForm as String)

msgbox "the value of field " & strField & _
" is = " & forms(strForm)(strField)

The above shows how you can pass a string field name, and string form name,
and then use the string as a value to ref forms etc. This concept works for
both forms, and controls/fields in a form.

Thus, you don't have to hard code refs to forms, or fields when calling the
routine.

You can always ref a field, or form as a sting at runtime like:

strForm = "Customer"
strField = "LastName"
msgbox "that value of field " & strField & " is " & forms(strForm)(strField)

So, you can have your on-action menus pass values to the code, and there is
no need to have a macro involved at all.

As mentioned, if you call the code directly from the on-action of the menu,
then your code can pick up the active form, and the active field anyway (and
thus, your menu DOES NOT even have to pass the form, or the active field
anyway).

So, I would suggest that you call the code directly from the menus, and not
even use the macros. It seems to me that would solve this problem.
 
Back
Top