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!

Selecting multiples for a question in a table???

Status
Not open for further replies.

valkyry

Technical User
Jan 14, 2002
165
US
Hi,
I can't think of it . . . I have a questionaire table and couple of the questions you can have mulitple answers from a list.

I can't think of how to select more then one from the list for the one field (question).

HELP????
 
1. Set up a Listbox with the various phrases:

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.

Rod
 
Hi, thanks for the info.

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).
 
Read the help files on: 'Multiselect Option'
and 'ItemsSelected Collection'

Be sure to study the examples for the latter - this should meet your needs.

Rod
 
Actually, I did from your suggestion in the 1st response. It didn't make sense to me, hence my response to yours.

Thanks
 
NOTE: I'm not a programmer and although the help files are showing me generally what to do and examples, I don't know how to implement them!

HELP!
 
OK here's an example I just worked up:

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.

Rod.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top