Creating a Drop down list where can pick more than one choice

J

Jessica

I would like to creat a dropdown list in which i can select more then one
option and have the options i selected display in a comment of box or text
box. The dropdown list will be a command button and when i click on it it
will display my dropdown list. I wish i can send and attachment of what i
need.
 
K

Ken Snell MVP

A combobox will not let you select more than one option. However, you can
have your choices be added to a textbox's string value as you make them:

Private Sub NameOfYourComboBox_AfterUpdate()
Me.NameOfTextbox.Value = (Me.NameOfTextbox.Value & vbNullString) & _
(Me.NameOfYourComboBox.Value & vbNullString)
End Sub


You'll need to ensure that your textbox is empty when you start. You can do
that manually or you can use a command button to empty the textbox:

Private Sub NameOfYourCommandButton_Click()
Me.NameOfTextbox.Value = Null
End Sub

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
 
A

Arvin Meyer MVP

That is not what a combobox does. You can however use a Listbox. Set the
multi-select property to either simple or extended.
 
J

Jessica

I need more clarification i need to create a combo box and a text box. For
example the name of my combo box is Diagnostic and the text box is call
description how will the formula look.
 
J

Jessica

It worked, but can i change the view of the combo box. Is there any way to
make it a link? I would like to be able to just click on the link to see my
choices select them and have them enter in my text box.
 
K

Ken Snell MVP

I don't understand what you mean by "a link". If you want to select all
items and then have them show up in a text box, you'll need to use a listbox
(as suggested by Arvin. You then will need code to "read" all the selections
in the listbox and put them in the text box. Post back if you want to use
this setup and need help with the code.
 
J

Jessica

your first suggestion worked, the problem was that in the form view both the
combo box and text box were display. i would like is to have a select button
that would display my list box then when the selection is made in the list
box it would transfer to the text box. If that is not possible send me the
code for the below
 
K

Ken Snell MVP

To use a command button to make your combobox visible for selecting an item,
then to have it become invisible after you make the selection:

Private Sub CommandButtonName_Click()
Me.NameOfYourComboBox.Visible = True
Me.NameOfYourComboBox.SetFocus
Me.NameOfYourComboBox.Dropdown
End Sub

Private Sub NameOfYourComboBox_AfterUpdate()
Me.NameOfTextbox.Value = (Me.NameOfTextbox.Value & vbNullString) & _
(Me.NameOfYourComboBox.Value & vbNullString)
Me.CommandButtonName.SetFocus
Me.NameOfYourComboBox.Visible = False
End Sub
 
J

Jessica

It worked perfectly, but i"m having a little problem when i run a query on a
specific
Diagnosis from the text box. is not showing me any records. I though that by
putting a comma after each diagnosis i pick from the combo box into the text
box i could run a query on a specific one but is not working.
 
K

Ken Snell MVP

You'll need to show what you're trying to do in the query based on what's in
the textbox. If you're separating the values with commas, you likely could
use the value from the text string in a "IN" clause string.
 
J

Jessica

for example in the textbox i have ADD,Anxiety, Depression, but i want to run
a query only on those kids that have a depression. When i run it nothing
comes up. Since the field have to much information on it.
 
K

Ken Snell MVP

How is your query supposed to be told that you only want it to look at one
of the three values in the textbox? How do you know which one you want to
use?
 
J

Jessica

if i decide to change my combobox to a list box to able to make mutiple
selections what would change from the below coding.
 
K

Ken Snell MVP

The changes needed depend upon how you want the list box to behave. Do you
want to make all the selections in the listbox first, then click a button to
copy them to the textbox? Or do you want each selection to appear in the
textbox as you select it in the listbox (and if this is what you want, how
should the form behave if you "unselect" an item in the listbox)?
 
J

Jessica

I want to click on the command button have the listbox appear then make all
the selection in the listbox and have then appear in the textbox when i'm
done selecting i want the listbox to be invisible. if i unselect an item i
want it to be removed automatically from my textbox,
 
K

Ken Snell MVP

The code for the command button, where we'll use the same command button to
do both tasks (make the listbox visible, and write the selected items into
the textbox):


Private Sub CommandButtonName_Click()
Dim strWhere As String
Dim varItemSel As Variant
Const strCommaBlank As String = ", "
strWhere = vbNullString
Select Case Me.ListBoxName.Visible
Case True
' build comma-separated list of items selected in listbox
For Each varItemSel In Me.ListBoxName.ItemsSelected
strWhere = strWhere & _
Me.ListBoxName.ItemData(varItemSel) & strCommaBlank
Next varItemSel
' strip off trailing comma and space
If Len(strWhere) > 0 Then _
strWhere = Left(strWhere, Len(strWhere) - Len(strCommaBlank))
Me.TextBoxName.Value = strWhere
Me.ListBoxName.Visible = False
Case False
' empty the textbox
Me.TextBoxName.Value = Null
' make listbox visible
Me.ListBoxName.Visible = True
' set focus to listbox
Me.ListBoxName.SetFocus
End Select
End Sub

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top