Selecting multiple Listbox items on form into table

hardrock

Registered User.
Local time
Today, 06:08
Joined
Apr 5, 2007
Messages
166
Hello, I am trying to move a record from Listbox0 on my form (containing 2 columns MachineModel and SerialNumber) into tb_machines1. In the code below, it works for rst!MachineModel but it does not for SerialNumber. Could someone please help me correct the code in bold below so it works ? Thanks

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tb_machines1")

RecCount = 0
For Each i In List0.ItemsSelected
'*******************
rst.AddNew
rst!MachineModel = List0.ItemData(i)
rst!SerialNumber = List0.ItemData(i)
rst.Update
RecCount = RecCount + 1
Next i
 
What is the data type of the SerialNumber column?
 
Hello, It is a string made up of 7 characters :)
 
Try this code.. I did not read your post properly.. Now going through I found it..
Code:
RecCount = 0
For Each i In List0.ItemsSelected
    rst.AddNew
    rst!MachineModel = List0.Column(0,List0.ItemData(i))
    rst!SerialNumber = List0.Column(1,List0.ItemData(i))
    rst.Update
    RecCount = RecCount + 1
Next i
Make sure that MachineCode is Column 1 and SerialNumber is in column 2 if it is the other way the code becomes..
Code:
RecCount = 0
For Each i In List0.ItemsSelected
    rst.AddNew
    rst!MachineModel = List0.Column(1,List0.ItemData(i))
    rst!SerialNumber = List0.Column(0,List0.ItemData(i))
    rst.Update
    RecCount = RecCount + 1
Next i
 
Hello :) I've just tried it but for some reason If I do a multiple select in my List0 box it only copies the first record to the table, nothing else i.e.If I select 3 unique records, it will copy 3 lots of the first highligted record?
 
I believe it is because you might have the Multi Select as Simple.. change it to Extended..
 
Defo set as "Extended" otherwise wouldn't be able to do multi select in list box.
 
Got it working. I removed the ItemData. Thanks for the heads up :)


rst!MachineModel = List0.Column(0, (i))
rst!SerialNumber = List0.Column(1, (i))
rst.Update
 

Users who are viewing this thread

Back
Top Bottom