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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReSetting an msoComboLabel-Item with flexible # of Items 1

Status
Not open for further replies.

waldemar

Programmer
Nov 15, 2001
245
DE
A couple of msoComboLabels (populated using .AddItem()) in my CommandBar are supposed to *remember* the values the user has chosen, so the next time he/she encounters that ComboBox already displays the last choice.

This is no problem as long as I am working with a fixed number of items. Saving the .ListIndex and reseting it that value does the job.

Unfortunately I also have Combo Boxes with a FLEXIBLE NUMBER (and ORDER!) of items; so using .ListIndex does not work here.
I would need another way to locate and reset to that item.

- The property .Text can be read (so I can *remember* it), but I can not SET it (Error 438)!
- I was thinking about maybe cycling through all available Items - comparing with the remembered .Text, so I get the proper .ListIndex. However I don't even find a way to do so (was hoping for some CommandBarControl.ITEMS(n).TEXT or similar)...

I was looking over all the Web, but it looks like nobody has worked this "way" with CommandBars; maybe someone here has any experience?
 
waldemar,

I'm not sure how you are implementing your CommandBarComboBox but try the following code snippet:

Code:
With CBO
  For i = 1 To .ListCount
    If LastSelectedItem = .List(i) Then
      .ListIndex = i
      Exit For
    End If
  Next i
End With

This assumes
Code:
CBO
(declared as CommandBarComboBox) has been Set to the appropriate ComboBox control. The variable
Code:
LastSelectedItem
contains the text of the list item previously selected by the user.

HTH
Mike
 
Thanks Mike - this .list(i) thing is exaaactly what I was looking for!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top