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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Select List Box 1

Status
Not open for further replies.

rosebud289

Programmer
Jan 13, 2005
25
0
0
US
How can I select multiple values within a list box and have all values inserted into the same field (separated by commas or semicolons)? I've tried changing "Multi Select" to simple and extended, but when I do so, I can select multiple values but the values are not placed in the desired field. Thanks!
 
Have your multi select property as simple, and use the "ctrl" key to select or dis-select each item.

Then if you use the following code in a command button etc to get the info that has been selected from the list box to a control

Code:
Dim var As Variant
Dim TestString

For Each var In ListBox.ItemsSelected
  TestString = ListBox.Column(0, var) & ";" & TestString
Next var

control = TestString

Hope this helps
 
One more question...when I select values then uncheck all of them, i receive an error message that says "run time error: field "fieldname" cannot be a zero-length string". How can i avoid this error? Thanks again for your help!!!
 
How are you updating the field with the value, where are you putting the code, in a command buttom, or on some other procedure??

I have just tested mine, to try and get the error message to see what is happening but am unable to get it.

 
I put it in "After Update". When you say command button, do you mean that i will have to click a button every time I update a record using the list box? Also, I noticed that when I move to the next record, the list box displays the values selected for the previous record.
 
Alter your code to:

Code:
Dim var As Variant
Dim TestString

For Each var In ListBox.ItemsSelected
  TestString = ListBox.Column(0, var) & ";" & TestString
Next var

    If TestString = "" Or IsNull(TestString) Then

        Else

        control = TestString 
    
    End If

To stop the select items been carried over to the next record use this in the form property on_current

listbox.rowsource = listbox.rowsource


hope this helps you,
 
When i inserted the listbox.rowsource = listbox.rowsource code in the "on current" section of the form, i receive the following error message: "Microsoft Visual Basic: Compile error: user-defined type not defined."

The code for the zero=length error worked. Thanks!
 
put the code after the after_update procedure with the other code, i know it works there.

What version of access are you using
 
ok one last try, but the "listbox.rowsource = listbox.rowsource" in the after_update procedure of the text box you are updating.

I still use A97. Sorry for any confussion.
 
Did you manage to solve the problem? Because I have the same problem as you and I'm still new to Microsoft Access 2000.

Thanks
 
How are ya rosebud289 . . . . .

Post the code as you have it now!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top