-
A simple problem, can't seem to find the solution
I'm trying to add a CommandBarComboBox to a custom command bar, and the command bar adds and populates fine, however i can't get it to fire its change event
VB Code:
'cbrCmdBar is my command bar
'commandbareventclass handles all the command bar events
Dim cBarCombo As CommandBarComboBox
Set cBarCombo = cbrCmdBar.Controls.Add(msoControlDropdown)
Set CommandBarEventClass.cBarBoxNavigation = cBarCombo
'CommandBarEventClass code is below
Public WithEvents cBarBoxNavigation As CommandBarComboBox
Public Sub cBarBoxNavigation_Change(ByVal Ctrl As Office.CommandBarComboBox)
msgBox "event fired"
End Sub
the event is not fired on teh change. I've used the same method to make command bar buttons and they work fine...so whats the deal with the combo box?? any help would be great, thanks
-
Re: A simple problem, can't seem to find the solution
the changed event only happens when you type something. If you are trying to find when the user selects another option, use the click event
-
Re: A simple problem, can't seem to find the solution
The CommandBarComboBox only has a change event, it is allegedly fired when someone makes a selection...alteast this is my understanding (and there is only 1 event selectable for it in visual studio)
-
Re: A simple problem, can't seem to find the solution
which program is this for?
-
Re: A simple problem, can't seem to find the solution
-
Re: A simple problem, can't seem to find the solution
Here is an MSDN example of exactly what i want to do, but the code simply doesn't work, the event does not get fired
http://msdn.microsoft.com/library/de...HV05250825.asp
frustrating... :confused:
-
Re: A simple problem, can't seem to find the solution
Did you code in the .OnAction property for the combo box?
-
Re: A simple problem, can't seem to find the solution
-
Re: A simple problem, can't seem to find the solution
There is only the Change event but it seems that the control is not linked to the event since there is no .OnAction property asigning the
sub to the event. ;) Depending on if this is an Add-In or Visio VBA you have the two syntaxes for it.
-
Re: A simple problem, can't seem to find the solution
That example pertains to Control Buttons (msoControlButton). I am currently using those and they are working fine
its the CommandBarComboBox that is giving me problem this problem
-
Re: A simple problem, can't seem to find the solution
But if your not assinging your .OnAction then it wont fire.
How does you code look like for adding the cbo?
-
Re: A simple problem, can't seem to find the solution
it must be the .OnAction event...I don't have it implemented now, what should i set it as?
-
Re: A simple problem, can't seem to find the solution
Depends. If you checkout the link smitty posted it shows the format. If its an add-in then "!<MyAddIn>" else if its Visio VBA
then "MyEventSub".
-
Re: A simple problem, can't seem to find the solution
Does the "MyEventSub" have to be in the same module as the place the command bar is created...if i want to you pass in paramteres can I pass in "MyEventSub(args)" ?
-
Re: A simple problem, can't seem to find the solution
It should be in the class where you have the cbo withevents. ;)
-
Re: A simple problem, can't seem to find the solution
ok, i am not getting it to work
this is my code in the setup class
VB Code:
Set cBarCombo = cbrCmdBar.Controls.Add(msoControlDropdown)
With cBarCombo
.Tag = "Navigate"
.Enabled = True
.OnAction = "cBarBoxNavigation_Change(cBarCombo)"
End With
PopulateNavigationBox cBarCombo
CommandBarEventClass.cBarBoxNavigation = cBarCombo
it errors on the .OnAction line
is this the wrong way/place to set this? i thought the chang event WAS the on action, it seems strange to me taht you would need to specify a sub if its a WithEvents object
-
Re: A simple problem, can't seem to find the solution
-
Re: A simple problem, can't seem to find the solution
Should be just...
VB Code:
.OnAction = "cBarBoxNavigation"
-
Re: A simple problem, can't seem to find the solution
Ok, this is what i've been trying:
I set up a method in my event handler class to sync the combo box, it looks like this
VB Code:
Public Sub SyncComboNav(box As Office.CommandBarComboBox)
Set cBarBoxNavigation = box
cBarBoxNavigation.OnAction = "cBarBoxNavigation_Change(cBarBoxNavigation)"
End Sub
this code: .OnAction = "cBarBoxNavigation"
said the method "OnAction" failed
however, this line
.OnAction = "cBarBoxNavigation_Change(cBarBoxNavigation)"
gave me an error saying "object required", which leads me to believe that
it sort of worked, but the parameter cBarBoxNavigation didn't work because
i've gotten that error before trying to use the combo box to get the text by doing
VB Code:
sMyText = cBarBoxNavigation.Text
in an event fired from a command button (this way i could have a button that says "GO" and it would fire on the event and then check the text of the combo, but this didnt' work eiither)
so i don't know what coudl be wrong still, or why it would say "object required' because the reference is not null
-
Re: A simple problem, can't seem to find the solution
You need to post more of your code so we can see what is actually going on.
You should not be setting the OnAction to the procedure name AND parameter.
-
Re: A simple problem, can't seem to find the solution
Ok here is the full deal
I have 2 class modules interacting here, one is to set up the command bar, the other is to handle the events. This is the code from the set up module:
VB Code:
Private cbrCmdBar As CommandBar
Private Sub SetupCommandBar()
Set cbrCmdBar = ovMyVisio.Application.CommandBars.Add(name:="Visual Mesa Navigation", Position:=msoBarTop, temporary:=True)
cbrCmdBar.context = Str(visUIObjSetDrawing) & "*"
cbrCmdBar.Protection = msoBarNoMove + msoBarNoChangeDock + msoBarNoCustomize
'I add a bunch of control buttons here, then the combo
dim cBarCombo as CommandBarComboBox
Set cBarCombo = cbrCmdBar.Controls.Add(msoControlComboBox)
Set CommandBarEventClass.cBarBoxNavigation = cBarDrop
'here ends my set up code, now for the event handling code
Public WithEvents cBarBoxNavigation As Office.CommandBarComboBox
Private Sub cBarBoxNavigation_Change(ByVal Ctrl As Office.CommandBarComboBox)
MsgBox "Do something!"
end sub
Hope that helps some, the event is just not firing on the change
-
Re: A simple problem, can't seem to find the solution
Is there any reason that you need the events in a secondary class? It only complicates things and you may be running multiple
instances of the combo so could be a possibility for not firing.
-
Re: A simple problem, can't seem to find the solution
I tried it in that same class and it still didnt' work, i don'[t think that is the problem
-
Re: A simple problem, can't seem to find the solution
Vhati did you ever get your combobox to work?