Multi-Select List Box - ERROR

  • Thread starter Thread starter BRENNON
  • Start date Start date
B

BRENNON

Yesterday there was a post which read: "Is there a way to
save data chosen from a multi-select list box in a single
table field? For example, in the list box, the user
chooses Animal, Inset, and Nature. The table then saves
all three of these choices in teh field "topic"."
----------------------------------------------------------
A response was posted which indicated to do the following:

Add a text box control to your form. Set its...
'ControlSource' property to 'Topic'
'Visible' property to 'No'
'Name' property to 'txtTopic'

use the AfterUpdate() event of your existing list box to
populate it.

Priveate Sub MyListBox_AfterUpdate()
Dim var as Variant
Dim ctl as ListBox
Dim str as String
For Each var in ctl.ItemsSelected
str- str & ";" & ctl.ItemData(var)
Next var
Me!txtTopic= Mid(str,2)
End Sub
 
I got the same message. I'm not very familiar with
code, so I'm not sure what piece is missing. Any ideas
from anyone? Or, since Douglas mentioned that this is a
violation of relational database theory, is there a way
to get each of the selected items to store in different
fields instead? For example, If the user chooses
Animals, Insects, and Nature, could Animals be saved in
Topic1, Insects in Topic2, and Nature in Topic3? I
really want to only use one list box if at all possible.

Thanks, Tara
 
Hi,
In the sample code, the listbox variable is never set to point to a specific
control.
You have to tell Access which listbox the variable represents.

Set ctl = Me.yourListbox

HTH
Dan Artuso, MVP
 
I got the same message. I'm not very familiar with
code, so I'm not sure what piece is missing. Any ideas
from anyone? Or, since Douglas mentioned that this is a
violation of relational database theory, is there a way
to get each of the selected items to store in different
fields instead? For example, If the user chooses
Animals, Insects, and Nature, could Animals be saved in
Topic1, Insects in Topic2, and Nature in Topic3? I
really want to only use one list box if at all possible.

This would be EXTREMELY bad design! No; if you have a one to many
relationship, use a one to many relationship. And the simplest tool
for manageing one to many relationships is a Subform.

If you really want a multiselect listbox, the posted code will do the
job - if you understand it and adapt it to *YOUR* database.
 
Back
Top