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

List Box on a Form - keep selection highlighted

Status
Not open for further replies.

michaellmn

Technical User
Feb 26, 2008
3
US
Hello,

I have a list box on a form that has choices that are dependent on a selection in another combo box. Everything seems to be working OK except for the fact that the selection in the combo box loses the highlighting when a user navigates to a different record. Is there a way to keep the user's selection highlighted in the combo box?

Best regards,
Michael
 
You can use the current event of the form to set the choices.
 
Remou, thank you very much for the reply.

Are you referring to the 'On Current' event? What kind of a macro or procedure would I use to set the choices? Would a 'refresh' command be sufficient to set the choices?

Thanks again for the help; I appreciate it.
 
How are ya michaellmn . . .

The hilite of the textbox portion of a combobox, follows standard access navigation, where how much is hilited is determined by Tools - Options - Keyboard Tab - Behavior entering field section. Any time the combobox loses focus to another record, field, subForm, or Form, the same will happen. This leaves you with quite a bit more to cover than may have been expected. [surprise]

Are you sure you want to go thru all that?

If you have the room, listboxes retain their selections!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thank you both, Remou and TheAceMan1, for your responses. I will see if I can apply one or both suggestions to my current database project. I am far from an expert, so it may take me a while to customize a solution. The selection behavior I was encountering seemed to be inconsistent when moving to different records.

Thank you both for your help.
 
First I do not know why the selection would un hilite because the normal behavior is they remain hilited. You must be requerying the form or the control is bound. I have some code below that allows you to save the selections to a public variable and a method to rehilite. There may be a better way.

Gentlemen,
In code how do you save the choices of a itemsSelected collection of multi-select listbox? This is how I did it and it may be a little clumsy. Is there a clone method for objects in VBA?

Code:
public colItems as collection

Private Sub reSelectItems()
 Dim varItem As Variant
 For Each varItem In colItems
   Me.lboEmployeeID.Selected(varItem) = True
 Next varItem
End Sub

Public Function cloneItemsSelected(theListBox As Access.ListBox) As Collection
  Set cloneItemsSelected = New Collection
  Dim varItem As Variant
  For Each varItem In theListBox.ItemsSelected
    cloneItemsSelected.Add varItem
  Next varItem
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top