Referencing the field ID in a multi-selection list box

Mr Clevver

Idiot Savant
Local time
Today, 10:28
Joined
Jun 26, 2008
Messages
17
Hi all.

I'm having a little issue with a multi-selection list box in a form which references a table (tCustomers) and determines what values are to be copied to a temporary table upon the clicking of a button. I have all the code up and running, and all seems good. However a little testing shows that rather than my code referencing the key field for the records depicted in the list box, it is actually referencing their place (i.e. if I change the list to sort by another field the code produces unexpected results). This isn't so terribly bad for the time being, but the staff using the system tend to have probing fingers and I shouldn't think it'd be too long until the records place in the list-box doesn't represent its customer_id (curse them all).

The part of the code which controls this is as follows:

Code:
With Me.LstInclude
        For Each varItem In .ItemsSelected
            If Not IsNull(varItem) Then
            stSQLInclude = "INSERT INTO tTempPrint ( Customer_id, 
Customer_name) SELECT tCustomers.Customer_id, 
tCustomers.Customer_name FROM tMailingLists INNER JOIN (tCustomers 
INNER JOIN tListAssign ON tCustomers.Customer_id = 
tListAssign.Customer_id) ON tMailingLists.List_id = tListAssign.List_id 
WHERE tMailingLists.List_id =" & varItem + 1
            DoCmd.RunSQL stSQLInclude
            End If
        Next
    End With
Is there any way I can get this to reference the Customer_id as found in the list-box, rather than its place (1st=0, 2nd=1 etc.)?


Hopefully that makes sense.
 
Try this:

.ItemData(varItem)
 
Thanks, that seems to have worked a treat - and saved me an innevitable headache some months down the road.
 

Users who are viewing this thread

Back
Top Bottom