multiselect list to create new records

P

Preston Bjorn

I'd like to use a multi-select list box to select from a pool of records,
and append the selections as new records in another table. Advice on how to
write this procedure? Examples?
 
D

Douglas J. Steele

Loop through the list box's ItemsSelected collection, and use the Column
property to get at the individual bits of selected data. Assuming you need
to take the contents of column 1 and 3 to form the basis of your new
records, your code could look something like:

Dim lngValue As Long
Dim strSQL As String
Dim varItem As Variant

lngValue = Me.SomeTextbox

For Each varItem In Me.MyListBox.ItemsSelected
strSQL = "INSERT INTO MyOtherTable(Field1, Field2, Field3) " & _
"VALUES(" & Me.MyListBox(0, varItem & ", " & _
Me.MyListBox(2, varItem) & ", " & lngValue & ")"
CurrentDb.Execute strSQL, dbFailOnError
Next varItem

Note that I'm assuming that all 3 fields in MyOtherTable are numeric. Note,
too, that column references in the Column property start at 0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top