469,323 Members | 1,493 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Screen.Active Identifying Form,SubForm,Control Names

I am using the Shortcut Menu Bar property of many combobox controls to
execute a single shared custom function.

When the function executes, I need it to immediately identify the
following items:
MainFormName, SubFormControlName (if this is a subform), and the
ComboBox Control Name that launched the event.

The following code seems to work, but I have my doubt. I am
particulary concerned about the subForm control identity. If the
function is launched from the Mainform instead of a subform, then
Line2 just displays the combobox control on the mainform, since no
subform control exists from that perspective.
So, assuming the code below is approaching this whole thing properly,
I would probably identify a subform when the controlnames for the last
two lines of code differ?

1-MsgBox Screen.ActiveForm.Name 'MainForm Name
2-MsgBox Screen.ActiveForm.ActiveControl.Name 'SubForm Control Name
3-MsgBox Screen.ActiveControl.Name 'Active Control name

Am I on the pursuing the properly ???

Thanks
Greg

Feb 15 '07 #1
3 9849
On Feb 15, 11:55 am, "ApexD...@gmail.com" <ApexD...@gmail.comwrote:
I am using the Shortcut Menu Bar property of many combobox controls to
execute a single shared custom function.

When the function executes, I need it to immediately identify the
following items:
MainFormName, SubFormControlName (if this is a subform), and the
ComboBox Control Name that launched the event.

The following code seems to work, but I have my doubt. I am
particulary concerned about the subForm control identity. If the
function is launched from the Mainform instead of a subform, then
Line2 just displays the combobox control on the mainform, since no
subform control exists from that perspective.
So, assuming the code below is approaching this whole thing properly,
I would probably identify a subform when the controlnames for the last
two lines of code differ?

1-MsgBox Screen.ActiveForm.Name 'MainForm Name
2-MsgBox Screen.ActiveForm.ActiveControl.Name 'SubForm Control Name
3-MsgBox Screen.ActiveControl.Name 'Active Control name

Am I on the pursuing the properly ???

Thanks
Greg

Have you tried climbing the object tree in reverse?
ActiveControl.Parent.Parent and so forth.
I would imagine you'd trap for an error when there are no more parent
objects, or check each iteration to see if it's the one you want.
Feb 15 '07 #2
Public Function fcnYourProc(ParamArray Elements()) As String
Dim i As Integer
For i = 0 To Ubound(Elements)
Debug.print Elements(i)
Next
End Function

Private Sub Combofrm1_Click()
Call fcnYourProc("Combofrm1", "MainForm", "FirstSubform")
End Sub

Private Sub Combofrm2_Click()
Call fcnYourProc("Combofrm2", "2ndForm", "2ndSubform", "text2")
End Sub
In your function you can declare a ParamArray argument that will take a
variable number of elements - you can pass 1 arg or multiple args as
show in the example above. The first sample passes 3 args, the 2nd
sample passes 4 args. So In each control that calls this function you
can hardcode the items you want the function to take and do stuff with.
You can even pass an array to ParamArray.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Feb 15 '07 #3
Thanks guys!
I climbed the Object tree in reverse.

Greg

Feb 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Sally | last post: by
3 posts views Thread by Simone | last post: by
4 posts views Thread by crystal | last post: by
1 post views Thread by veteranwebdesign | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.