FindControl property help - what type? |
Post Reply |
Author | |
blockwood
Groupie Joined: 23 March 2004 Status: Offline Points: 45 |
Post Options
Thanks(0)
Posted: 07 April 2004 at 3:30pm |
what is the proper code to find this control
Here is the code that builds this control: ID_RUN_LOAD_TABLES Set ControlRun = c.ActiveMenuBar.Controls.Add(xtpControlPopup, 0, "&Run", -1, False) With ControlRun.CommandBar.Controls .Add xtpControlButton, ID_RUN_LOAD_TABLES, "Load Tables", -1, False .Add xtpControlButton, ID_RUN_COMPARE, "Compare", -1, False .Add xtpControlButton, ID_RUN_STOP, "Stop", -1, False .Add xtpControlButton, ID_RUN_SHOW_LOAD_OPTIONS, "Object Compare Options", -1, False End With this code returns nothing no matter what I do. I have experimented with different property types but nothing works. It is a file menu control Set cdjControl = CommandBars.FindControl(xtpBarTypePopup, ID_RUN_LOAD_TABLES) If Not cdjControl Is Nothing Then cdjControl.Enabled = False End If it is a file menu control |
|
SuperMario
Admin Group Joined: 14 February 2004 Status: Offline Points: 18057 |
Post Options
Thanks(0)
|
Try this:
Set cdjControl = CommandBars.ActiveMenuBar.FindControl(, ID_RUN_LOAD_TABLES,,True) If Not cdjControl Is Nothing Then cdjControl.Enabled = False End If Edited by SuperMario |
|
blockwood
Groupie Joined: 23 March 2004 Status: Offline Points: 45 |
Post Options
Thanks(0)
|
that did the trick. in under 5 minutes response time!
|
|
asd123456789
Newbie Joined: 12 May 2004 Location: China Status: Offline Points: 10 |
Post Options
Thanks(0)
|
The method Find and FindControl is returned one control only.if two controls uesed same Id,the second one is not returned. |
|
asd123456789
Newbie Joined: 12 May 2004 Location: China Status: Offline Points: 10 |
Post Options
Thanks(0)
|
The method Find and FindControl can not find top level menu. |
|
SuperMario
Admin Group Joined: 14 February 2004 Status: Offline Points: 18057 |
Post Options
Thanks(0)
|
To find top level controls you must manually set an Id to those controls.
Set ControlRun = c.ActiveMenuBar.Controls.Add(xtpControlPopup, 0, "&Run", -1, False) ControlRun.Id = ID_RUN With ControlRun.CommandBar.Controls .Add xtpControlButton, ID_RUN_LOAD_TABLES, "Load Tables", -1, False .Add xtpControlButton, ID_RUN_COMPARE, "Compare", -1, False .Add xtpControlButton, ID_RUN_STOP, "Stop", -1, False .Add xtpControlButton, ID_RUN_SHOW_LOAD_OPTIONS, "Object Compare Options", -1, False End With And, Yes, only one control is returned with the find method. You can just use a "for each" statement to look for them all, or search each command bar individually. |
|
asd123456789
Newbie Joined: 12 May 2004 Location: China Status: Offline Points: 10 |
Post Options
Thanks(0)
|
Thanks for SuperMario help! "for each" is very good.
|
|
asd123456789
Newbie Joined: 12 May 2004 Location: China Status: Offline Points: 10 |
Post Options
Thanks(0)
|
I finding the control for set the Enbaled and the Visible. I want do it like this: Commandbars.ActiveMenuBar.Controls(ID_RUN_LOAD_TABLES).Enabl ed=TRUE Commandbars.ActiveMenuBar.Controls(ID_RUN_LOAD_TABLES).Visib le=TRUE Reference ActiveBar please. |
|
SuperMario
Admin Group Joined: 14 February 2004 Status: Offline Points: 18057 |
Post Options
Thanks(0)
|
'When you create the control, you must manually set the Id property if this is a top level control like this:
Dim ControlRun as CommandbarControl Set ControlRun = CommandBars.ActiveMenuBar.Controls.Add(xtpControlPopup, 0, "&Edit", -1, False) ControlRun.Id = ID_RUN_LOAD_TABLES 'Then in your execute event you can add something like this to find the control and enable/disable. Set Control = CommandBars.ActiveMenuBar.FindControl(, ID_RUN_LOAD_TABLES , True) If Not Control Is Nothing Then Control.Enabled = False End If When controls are added to a commandbar such as the active menubar, they can be referenced by the index, which is assigned by the order that the controls were added starting at 1. So you would need to use the index of the control if you are referencing it directly, for example: CommandBars.ActiveMenuBar.Controls(2).Enabled = False This line of code disabled the second control in the active menubar. You can use the index of a control once you find it. Set Control = CommandBars.ActiveMenuBar.FindControl(, ID_RUN_LOAD_TABLES , True) If Not Control Is Nothing Then CommandBars.ActiveMenuBar.Controls(Control.Index).Enabled = False End If Hope this helps. Edited by SuperMario |
|
blockwood
Groupie Joined: 23 March 2004 Status: Offline Points: 45 |
Post Options
Thanks(0)
|
"And, Yes, only one control is returned with the find method. You can just use a "for each" statement to look for them all, or search each command bar individually."
Can you show how to do this? The common task to is enable a File Menu Item AND a toolbar button with the same ID (as often they are shown in menu AND toolbar) to do this I use the following. One block of code seems to work for toolbars and the other seems to work for Menus but it sounds as if there is a better way to do it. This code is used to Show/Hide certain controls Public Function ShowCodeJockControl(c As CommandBars, id As Long, bolOn As Boolean) Dim Control As CommandBarControl ' For toolbar Set Control = c.FindControl(, id, , True) If Not Control Is Nothing Then Control.Visible = bolOn End If ' For File Menu Set Control = c.ActiveMenuBar.FindControl(, id, , True) If Not Control Is Nothing Then Control.Visible = bolOn End If End Function |
|
blockwood
Groupie Joined: 23 March 2004 Status: Offline Points: 45 |
Post Options
Thanks(0)
|
i never got reply to my last question
|
|
skluc
Newbie Joined: 19 May 2004 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
I also wait for an answer to the question by blockwood. How use the for each to navigate the commandbar? The solution by blockwood is good for a tool thati is in the activebar and in ONE toolbar. But if the same tool is in more toolbar? |
|
asd123456789
Newbie Joined: 12 May 2004 Location: China Status: Offline Points: 10 |
Post Options
Thanks(0)
|
I was sovled this problem by my code. |
|
skluc
Newbie Joined: 19 May 2004 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
where can we see your code?
|
|
asd123456789
Newbie Joined: 12 May 2004 Location: China Status: Offline Points: 10 |
Post Options
Thanks(0)
|
1:Create a list to hold all ID and controls added. 2:Seek the list by ID to found controls one by one. 3:Set Property of controls found.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |