Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Multiselection saved to table?

cameling4funcameling4fun Member Posts: 1
I am creating a database to track classes and attendants. I want to create a multiselect listbox, and have it save to the table. Basically, this is what I have so far ( to keep it simple until I understand)

Relationships 1-many
class table
emp table

1 class to many employees.

Class table has classid#, date, instructor, time began, time ended as fields


Employee table has empid#, name, class#

I created a seperate table to just hold employees(students)names. I can get the listbox to list their names, but the multiselection does not save anywhere. I would like it to save in the employee table with name, class#.

Thank you,

Bill

Comments

  • dokken2dokken2 Member Posts: 532
    a multiselect listbox can not "bind" multiple selected values to the single field it is bound to, ie: you can't listen to 3 stations at the same time on a radio, you have to switch between them

    what you need to do-

    loop thru the listbox items
    determine if item is selected or not
    insert selected records into a table

    [code]
    'SHOW WHAT IS SELECTED
    For i = 0 To Me.List0.ListCount - 1
    If Me.List0.Selected(i) Then MsgBox Me.List0.ItemData(i)
    Next
    Exit Sub

    'INSERT SELECTED INTO A TABLE
    Dim rec As String
    Dim sql As String
    For i = 0 To Me.List0.ListCount - 1

    If Me.List0.Selected(i) Then
    rec = Me.List0.ItemData(i)

    sql = "INSERT INTO Table2 ( PC_NAME )" & _
    " SELECT " & rec & " AS expr1;"
    DoCmd.SetWarnings False
    DoCmd.RunSQL sql
    DoCmd.SetWarnings True
    End If
    Next
    [/code]
Sign In or Register to comment.