In a post on some board I can no longer find, someone asked a question about picklists and how to move the items between the lists.
Having just worked on something utilizing a Scripting Dictionary object, I had a thought about implimenting a dictionary object in a custom class
with a pick list. It's extremely easy to add and remove values from dictionaries so I thought I'd give it a go.
I'd be interested in hearing any ways to add to or improve its functionality.
The 2 lines of code in your form module are shown below.
The only arguments passed to the Class are the listbox objects.
Code:
Option Compare Database
Option Explicit
Dim clsPL As New clsPickList 'instaniate the class
Private Sub Form_Load()
clsPL.InitMyClass Me.List4, Me.List6 'initiate the instance
End Sub
If this helped, please click the star * at the bottom left and add to my reputation- Thanks
There used to be a great video on displaying and moving things from 1 list to another. That was on the DataPig website which has been taken down over the last couple of years.
I made a few changes to my first version above.
I added comments to the class module for easier understanding and a little code modification.
There is now no need to set the column count or column widths of the rightside (selected items) listbox and
no rowsource is required. Just drop a blank listbox on your form and size it as needed. The settings are copied over
from the leftside (selections) listbox to the rightside listbox.
I originally thought that applying a where clause to the leftside listbox's rowsource would cause a problem with the
procedure that modifies the rowsource but that doesn't seem to be the case so far. It doesn't seem to matter as long as the
rowsource is based on a table with the primary key field in the first column. I'll need further testing to see just how complicated
a where clause can be.
Added a function to return the value of the selected items and the ability to test the different optional arguments.
The function has 4 optional arguments.
intColumn to select the column to return. Defaults to column(0)
delimiter to delimit the return values. Defaults is nothing. Can use to delimit dates with octothorpes(#) or strings with quotes(")
separator to chose the separating character. Defaults to comma(,). Can use Pipes(|) or any other string.
autoreset as boolean. To determine whether to clear the selected list when function is run.
I also added another table and the ability to switch the rowsource of the listboxes just to demonstrate date datatypes
and delimiting them with octothorpes.
If this helped, please click the star * at the bottom left and add to my reputation- Thanks