1;"yes";2;"No";3;"Haven't got a clue";4;"What's my name?"
Set the ListBox's Multiselect property to 1 (i.e. Simple) so questioneers can select Yes and No - literally.
Read the Access help files on Multiselect and ItemsSelected to get some ideas on how to gather the selected items for insertion into your table.
You might set up a field for each selectable option, effectively treating each option as a separate question.
Set the field types as Number or Text if you want to store a number representing the item's position in the list; or Text if you want to store the actual phrase itself (might be a waste of space if you've got many thousands of records); or a Yes/No type if you just want a flag to show whether a particular option was chosen.
Use a loop in the on exit event of the list box to cycle through the list checking which ones were selected and updating the relevant fields. I am assuming that the actual fields storing the results will be hidden on the form while the list box is there just used to gather the individual's views.
Note that any multiselcted items on a list box will be lost if the list box is requeried.
I was hoping to find a code that will take the selected items from multiselect list box and put them in one field by combing them with a / for each selection.
e.g. email/phone/fax (as the 3 answers selected for that one question and puts that into a field called ContactVia or something).
I suggest to create this using a new blank form, then play around with it till you get the hang of it.
First create a List-Box called ColourList and populate it with a list of colours (do these mean anything to you I wonder?):
Black
Brown
Red
Orange
Yellow
Green
Blue
Violet
Grey
White
Set the list box's Multi-Select option to Simple
Next create a textbox called txtMyColours and copy the following code to the form's module:
Private Sub txtMyColours_Enter()
Dim ctl As Control
Dim varItm As Variant
Set ctl = Me.Form!ColourList
txtMyColours = ""
For Each varItm In ctl.ItemsSelected
txtMyColours = txtMyColours & IIf(txtMyColours = "", "", "/" & ctl.ItemData(varItm)
Next varItm
End Sub
What this does.
Click on two or three of the colours in the list, then click in the text box. Hey presto the selected colours are listed in the text box: a/b/c.
That's the good part - the bad part is I haven't figured out how to reset the listbox automatically with code so as to clear the selected items. VBA Help explains how to do it if the Multi Select option is set to Extended but the Extended method of operation is too fiddly for your needs I think.
If anyone reading this can explain how to clear the List-Box selections - without having to close the form and re-open it - speak up please.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.