Data entry base on Listboxes

S

SF

Hi,

I have an entry form consist of two listboxes, one for districts and another
one for communes. Both listboxes is set to allow multiple selection. Based
on the selected communes, I want to add these record to a table, my table
consist of 4 fields, \

ID AutoNumber
P_ObjectID Number Foreign key
P_DistrictID Number
P_CommuneID Number Foreigh Key link to Commune Table


My Commune Listbox has 3 columns

CommuneID;Commune Name;District Code

Thorugh code below, I get Object Not found!


Dim varItem As Variant
Dim dbs As DAO.Database
Dim rstLocation As DAO.Recordset

Set dbs = CurrentDb

Set rstLocation = dbs.OpenRecordset("tblProjectLocations", dbOpenDynaset)
With rstLocation
For Each varItem In Me.lstCommuneID.ItemsSelected
.AddNew
![P_ObjectID] = 5 'varObjectID
![P_DistrictID] = Me.lstCommuneID.Column(2).ItemData(varItem)
=============> I get error here
'.Column(2) ' .Column(2)
![P_CommuneID] = Me.lstCommuneID.ItemData(varItem) '.Column(0)
.Update
Next varItem
End With
 
D

Douglas J. Steele

To refer to a specific column of the selected item, you need to use

Me.lstCommuneID.Column(2, varItem)
 

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