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

listbox selection is lost after requery

Status
Not open for further replies.

breemersch

Programmer
Apr 23, 2009
3
BE
hi,

I have a listbox (multiselect: extended) in Access.
You can select one or more lines and view those more in detail in a new form.
When closing this form, the list is requeried, but then the selection gets lost.

The listbox used to be a multiselect : simple. Then there was no problem, the selection wasn't lost.

Any idea on how to keep my selection?

Thanks,
Christophe
 
Any idea on how to keep my selection
don't requery ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The requery is necessary to view the changes the user made...
 
How are ya breemersch . . .

Try the following in the [blue]On Close[/blue] event of the new form ([blue]you![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]   Dim LBx As ListBox, Build, idx, Ary
   
   Set LBx = Forms![purple][B][I]FormName[/I][/B][/purple]![purple][B][I]ListboxName[/I][/B][/purple]
   
   [green]'Hold selected indices[/green]
   For Each idx In LBx.ItemsSelected
      If Build <> "" Then
         Build = Build & "," & idx
      Else
         Build = idx
      End If
   Next
   
   [green]'Requery the Listbox[/green]
   LBx.RowSource = LBx.RowSource
   
   [green]'Setup array of indices[/green]
   Ary = Split(Build, ",")
   
   [green]'Restore selections[/green]
   For idx = LBound(Ary) To UBound(Ary)
      LBx.Selected(Ary(idx)) = True
   Next
   
   Set LBx = Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top