Listbox - Saving last 10 selected

  • Thread starter Thread starter Flannel
  • Start date Start date
F

Flannel

I am hoping someone can point me in the right direction for
this. I'm not sure how easy or hard it is to do.

I have a list box of companies. When I select a company
from the list box it displays the rest of the company
information for the company on the form. This works fine. I
would like to be able to store the last 10 companies that
were selected in a new list box on the same form, it would
be like a "most recently selected companies" list. So, when
I select a company that companies ID field and name would
be put into the new list box.

I'm not sure where to even start for this. Is there someway
I could store the last 10 in memory, or would I have to
create a new table to store them in? I haven't played with
the BOOKMARK
 
Ensure your destination list box has its row source type set to value list.
You can now manipulate the string within the list box's row source. This
string needs to be a semi-colon delimited list of items. As you have 2
columns then two items will form a single row in the list box.

To add an item just append them to the row source. Likewise to remove an
item, when your limit of 10 is exceeded, remove the first pair of items.
You'll need to use various string manipulation functions.... hang on, I'll
give it a go!

Say the source listbox is called lstAll and the destination is called
lstRecent... I think the After Update event of lstAll is the best spot for
the code...

'----------------------------------------------------
'work with the destination listbox
With lstRecent

'add selected item
..RowSource = .RowSource & lstAll.Column(0, lstAll.ListIndex) & ";" &
lstAll.Column(1, lstAll.ListIndex) & ";"

'remove first list item if more than 10 list items (as there are two columns
we actually remove 2 items).
If .ListCount > 10 Then
.RowSource = Right(.RowSource, Len(.RowSource) - InStr(1, .RowSource,
";", 0))
.RowSource = Right(.RowSource, Len(.RowSource) - InStr(1, .RowSource,
";", 0))
End If

End With
'---------------------------------------------------

I haven't tested this...

HTH
Sam
 
Sam D said:
Ensure your destination list box has its row source type set to value list.
You can now manipulate the string within the list box's row source. This
string needs to be a semi-colon delimited list of items. As you have 2
columns then two items will form a single row in the list box.

To add an item just append them to the row source. Likewise to remove an
item, when your limit of 10 is exceeded, remove the first pair of items.
You'll need to use various string manipulation functions.... hang on, I'll
give it a go!

Say the source listbox is called lstAll and the destination is called
lstRecent... I think the After Update event of lstAll is the best spot for
the code...

There is a routine in the Access Developer's Handbook which uses the tab
function to manipulate data.
It handles inserts and deletions and might be worth looking at.
 
Back
Top