Re: Creating a Drop down list where can pick more than one choice
- From: "Ken Snell MVP" <kthsneisllis9@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 21 Apr 2009 18:06:00 -0400
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/
"Jessica" <Jessica@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:674ADFD2-0BF7-4D34-A850-FF018E4682E9@xxxxxxxxxxxxxxxx
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,
"Ken Snell MVP" wrote:
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)?
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
"Jessica" <Jessica@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7C00FCD9-BE0A-4228-A550-631411EFD014@xxxxxxxxxxxxxxxx
if i decide to change my combobox to a list box to able to make mutiple
selections what would change from the below coding.
"Ken Snell MVP" wrote:
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
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
"Jessica" <Jessica@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EF45B2BC-2E5C-4A62-A223-83FAB8EC6E68@xxxxxxxxxxxxxxxx
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
"Ken Snell MVP" wrote:
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.
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
"Jessica" <Jessica@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2E3B6F3F-438A-4E0B-BA05-D381C695EE51@xxxxxxxxxxxxxxxx
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.
"Ken Snell MVP" wrote:
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/
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
"Jessica" <Jessica@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:25F3ED8F-D9AF-4B59-B526-C73DB9B0FD9D@xxxxxxxxxxxxxxxx
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.
.
- References:
- Creating a Drop down list where can pick more than one choice
- From: Jessica
- Re: Creating a Drop down list where can pick more than one choice
- From: Ken Snell MVP
- Re: Creating a Drop down list where can pick more than one choice
- From: Jessica
- Re: Creating a Drop down list where can pick more than one choice
- From: Ken Snell MVP
- Re: Creating a Drop down list where can pick more than one choice
- From: Jessica
- Re: Creating a Drop down list where can pick more than one choice
- From: Ken Snell MVP
- Re: Creating a Drop down list where can pick more than one choice
- From: Jessica
- Re: Creating a Drop down list where can pick more than one choice
- From: Ken Snell MVP
- Re: Creating a Drop down list where can pick more than one choice
- From: Jessica
- Creating a Drop down list where can pick more than one choice
- Prev by Date: RE: Restrict Specific Characters from Form
- Next by Date: Re: Conditional formatting
- Previous by thread: Re: Creating a Drop down list where can pick more than one choice
- Next by thread: Re: Creating a Drop down list where can pick more than one choice
- Index(es):
Loading