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

Unbound listbox to table 1

Status
Not open for further replies.

Leventcos21

Technical User
Oct 7, 2004
77
US
Hi, I have 2 unbound listboxes, 1 list box contains the items and the other contains what items have been selected.

How can I the items in listbox 2, into a table. Right now, when I change the records, the listboxes remain the same
 
This code below inserts a new record into a table for every item that is selected in the list box. The code is attached to a command button. Also make your second listbox a bound field to the table.

'Counts the number of rows selected in the list box
For i = 0 To Me.lstItemValue.ListCount - 1
If Me.lstItemValue.Selected(i) = True Then

'Inserts new records into the table based on how many items are selected in the list box
DoCmd.RunSQL "INSERT INTO tblExclusion(State, Event," & _
" Year, RevisingCode, ItemName, ItemValue, Comment, SubmittedBy," & _
" SubmittedDate, LastModifiedBy, LastModifiedDate)" & _
" VALUES( '" & strState & "','" & strEvent & "','" & strYear & "'," & _
"'" & strRevisingStatus & "','" & strItemName & "','" & Me.lstItemValue.ItemData(i) & "'," & _
"'" & strComments & "','" & strSubmittedBy & "','" & dteSubmittedDate & "'," & _
"'" & strLastModified & "','" & dteLastModifiedDate & "');"

End If
Next i

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top