G
Guest
Hi,
If you are like me and you wish you had an easy way for Access to "see" what
form or subform currently has the focus so you can use that info in shortcut
routines for instance, I came up with an easy fix.
Lets say your Main form is call "Main", your first subform is called "Data1"
and your subform on Data 1 is called "DataSub1".
Ok now lets say you've written ur database so that the subforms can be
changed to show any number of forms. The are changed by changing the
..sourceobject using code.
Let's also say that you have written a Shortcut Menu that you want to be
able to work anywhere, no matter where your form is located, Data1 or
DataSub1. The problem is that if you want to perform actions on your subform
using your shortcut menu, if Access doesn't know the current "address" of the
form, its doesn't know what to do.
SOLUTION:
Ok, here is my fix. It's easy actually. Start by creating a 2 Global
Variables like so:
Dim vfrmObject as Object
Dim vfrmName as String
Now on the OnEnter event for your subform simply change vfrmObject to the
location address and vfrmName to the "name" of the location.
For example. If My form "frmPhoneNumbers" is located in subform "Data1" on
my Main form, I set vfrmObject to equal Forms![Main]![Data1] and vfrmName =
"Data1" when I enter Data1, like so:
Set vfrmObject = Forms![Main]![Data1]
vfrmName = "Data1"
Now if I want to create a shortcut menu for my form "frmPhoneNumbers" that
will work if it happens to be in Data1, I just use the following:
With vfrmObject
..form![phonetype] (the field I want to change) = "Home Phone"
end with
Now no matter which subform your frmPhoneNumbers phone is in, Access will
see the address correctly.
WHAT ABOUT SUBFORMS WITHIN SUBFORMS:
No problem, set the OnEnter event for your subform as follows:
Select Case vFrmName
If you are like me and you wish you had an easy way for Access to "see" what
form or subform currently has the focus so you can use that info in shortcut
routines for instance, I came up with an easy fix.
Lets say your Main form is call "Main", your first subform is called "Data1"
and your subform on Data 1 is called "DataSub1".
Ok now lets say you've written ur database so that the subforms can be
changed to show any number of forms. The are changed by changing the
..sourceobject using code.
Let's also say that you have written a Shortcut Menu that you want to be
able to work anywhere, no matter where your form is located, Data1 or
DataSub1. The problem is that if you want to perform actions on your subform
using your shortcut menu, if Access doesn't know the current "address" of the
form, its doesn't know what to do.
SOLUTION:
Ok, here is my fix. It's easy actually. Start by creating a 2 Global
Variables like so:
Dim vfrmObject as Object
Dim vfrmName as String
Now on the OnEnter event for your subform simply change vfrmObject to the
location address and vfrmName to the "name" of the location.
For example. If My form "frmPhoneNumbers" is located in subform "Data1" on
my Main form, I set vfrmObject to equal Forms![Main]![Data1] and vfrmName =
"Data1" when I enter Data1, like so:
Set vfrmObject = Forms![Main]![Data1]
vfrmName = "Data1"
Now if I want to create a shortcut menu for my form "frmPhoneNumbers" that
will work if it happens to be in Data1, I just use the following:
With vfrmObject
..form![phonetype] (the field I want to change) = "Home Phone"
end with
Now no matter which subform your frmPhoneNumbers phone is in, Access will
see the address correctly.
WHAT ABOUT SUBFORMS WITHIN SUBFORMS:
No problem, set the OnEnter event for your subform as follows:
Select Case vFrmName