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

multiselect List or Combo Box 2

Status
Not open for further replies.

craftk

Programmer
Mar 19, 2003
12
US
Hi,
I have a form that adds information about our donors. In this form I have a List box that looks up the values in a table called "Category LookUP Table". I store that value in a table called "Add Names" in a field called "Category". I would like to be able to select more then one item from the list box and store it in my "Add Names" table in the field called "Category" like this.

Hotel, Boardmember, VIP

Can anyone help?
 
In the click event for a button you could put this type of code.

Dim strVal as String
Dim varItem as Variant
Dim ctl as Control
Dim rst as DAO.Recordset
Set ctl = Me.ListBoxName
For Each varItem in ctl.ItemsSelected
strVal = strVal & ctl.ItemData(varItem) & ", "
Next
strVal = Mid(strVal,1,Len(strVal)-2)

Set rst = CurrentDb.OpenRecordset("Add Names")
rst.AddNew
rst!Category = strVal
rst.Update

Set rst = Nothing
Set ctl = Nothing

Paul
 
I copyed your code in the click event on a comand button and changed the "me.listboxname" to "me.list6", but it still only inserting one category name. What am I doing wrong?

Thanks
 
Is the multi select set to Simple or Extended? When you select multiple values, are they all highlighted? It should run just fine. Post the code you are using.

Paul
 
Hi Guys,

Here is what I would like to accomplish but I'm not sure how to go about it. I want to create something like a combo box where you select a single entry and depending on what I what is chosen it present a new list where you can select something else. I would want this to go several levels deep.

The database is being designed to track computer issues and I want to have this box record what the computer problem is. For example, If I have a boot problem with a PC I'd like to be able to select boot from a drop down list and have it present another list of boot problems like no power. Once I select this it opens another list of reasons for now power like power supply. Finally, I'd want this recorded in back to the table.

Any input or ideas would be appreciated. Keep in mind I am just a novice VB programmer but I'm learning in a hurry :)

Thanks.
 
Sorry previous post went as a reply when meant to post it as a question. I've re-posted this qustion in the correct spot.
 
The multi select is set to Simple and when you select multiple values, they all highlight. But when I go to my table the Category field is blank.

Thanks
 
Here's the code:

Private Sub Command14_Click()
Dim strVal As String
Dim varItem As Variant
Dim ctl As Control
Dim rst As DAO.Recordset
Set ctl = Me.List10
For Each varItem In ctl.ItemsSelected
strVal = strVal & ctl.ItemData(varItem) & ", "
Next
strVal = Mid(strVal, 1, Len(strVal) - 2)

Set rst = CurrentDb.OpenRecordset("Add Names")
rst.AddNew
rst!Category = strVal
rst.Update

Set rst = Nothing
Set ctl = Nothing

End Sub

Thanks

 
I don't see anything wrong at all. I copied it and ran it and got a new record in my table with the values I expected. I assume that the field you are inserting these values into is a Text field. Check to make sure the field size in the Table is big enough to handle all the info you are putting in the field.
Do you know how to set a Break Point and step thru your code? If you can, it will help sort this out.

Paul
 
I don't know what is intended here... If all selected items should go into one record, the code is OK and probably the field size is too small.
If it should enter each item as a new record, then:

Private Sub Command14_Click()
Dim strVal As String
Dim varItem As Variant
Dim ctl As Control
Dim rst As DAO.Recordset
Set ctl = Me.List10

Set rst = CurrentDb.OpenRecordset("Add Names")

For Each varItem In ctl.ItemsSelected
strVal = strVal & ctl.ItemData(varItem) & ", "
strVal = Mid(strVal, 1, Len(strVal) - 2)
rst.AddNew
rst!Category = strVal
rst.Update

Next

Set rst = Nothing
Set ctl = Nothing
End Sub

Or I have entirely missed the point...

[pipe]
Daniel Vlas
Systems Consultant
 
What I was doing wrong was adding a new record, when I needed to edit a record. So I changed this code "rst.AddNew" to "rst.Edit" and it worked great. Thank you so much for you help. You were very helpful and very fast. I gave you a Big Star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top