Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange state exception

Status
Not open for further replies.

deusaquilus

Programmer
Feb 2, 2008
1
US
When trying to call at CommandBar object state change, i get a "Method 'State' of object '_CommandBarButton' failed" exception.

The code is fairly simple, it goes as follows

Dim hideDeleted As CommandBarButton
Set hideDeleted = ActiveExplorer.CommandBars("Current View").Controls.Item(2)
hideDeleted.State = msoButtonDown <-excepts here

What am I doing wrong?
 




Hi,

What application?

Have you checked help on ActiveExplorer?

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Looks like Outlook.

I am not sure why it is doing this, but it certainly does do it. say I have Inbox as my View, and Messages is the Current View, and it is #3 (third) in the menu list:
Code:
Dim hideDeleted As CommandBarButton
Set hideDeleted = ActiveExplorer _
   .CommandBars("Current View").Controls.Item(3)
msgbox hideDeleted.State & vbTab & hideDeleted.Caption
will display:

-1 Messages

msoButtonDown is indeed -1.

Say I change it to Last Seven Days = Item(5). But I run the code on Item(3) still. The display is:

0 Messages

msoButtonUp is indeed 0.

HOWEVER, as you have discovered, you can not explicitly set the State via code. WHY? I have no idea, maybe because menu items are not, technically buttons?

HOWEVER (#2): you can in fact make the State at least Down (the current view) with another method, Execute.
Code:
ActiveExplorer.CommandBars("Current View") _
   .Controls.Item(2).Execute
will make the second item the CurrentView (ie. State = msoButtonDown).


The weird thing is that .Execute seems to destroy the object.
Code:
Dim hideDeleted As CommandBarButton
Set hideDeleted = ActiveExplorer _
   .CommandBars("Current View").Controls.Item(2)
Msgbox hideDeleted.State & vbTab & hideDeleted.Caption
hideDeleted.Execute
Msgbox hideDeleted.State & vbTab & hideDeleted.Caption
Say item(2) is NOT selected, and you get messages on its State.

First message: 0 yaddaYadda (whatever)
.Execute
Second message.....fails "Object required"

yet .Execute does work. If you query .State again, it will be -1. Execute only makes it True (-1), it will not make it msoButtonUp.

Search me. I do not know why.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top