help with Code

S

SF

Hi,

I have a form with 2 cascade comboboxes for Provinces and Districts and 1
listbox to list all Communes for the seleted districts. User can select
multiple commune before click the Save button (with code below). I want to
save only the selected communes but as a result, all the communes in the
listbox are saved in the table. What is wrong with my code?


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

DoCmd.Hourglass True
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblTargetCommunes", dbOpenDynaset)

With rst
For Each varItem In Me.TC_CommuneID.ItemsSelected
.AddNew

![TC_ContactID] = Me.TC_ContactID
![TC_CommuneID] = Me.TC_CommuneID.ItemData(varItem)
![TC_DistristID] = Me.TC_DistristID
![TC_ProvinceID] = Me.TC_ProvinceID
![TC_Year] = Me.TC_Year
![TC_Owner] = CurrentUser ' Me.TC_Owner
![TC_Remarks] = Me.TC_Remarks
![DateUpdate] = Now()
![TC_PactUnitID] = Me.TC_PactUnitID
.Update
Next varItem
End With
rst.Close
DoCmd.Hourglass False
MsgBox "Data is saved", vbOKOnly, "Data Saved"
DoCmd.Close

SF
 
D

Douglas J. Steele

It would help if you told us what problem you're experiencing with the code!
 

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

Similar Threads

Help with code 5
Help Error 3146 ODBC call fail 0
Data entry base on Listboxes 1
Help with Code 1
Invalid Use of Null 3
Combo Box with a event procedure 1
Make table from recordset 2
Command Button 0

Top