looping through all items in a list box (1 Viewer)

cocowomble

Registered User.
Local time
Yesterday, 21:24
Joined
May 25, 2014
Messages
25
hi all.

I'm struggling with what is probably a very simple solution, and would like some help.

I have managed to amend records based on the user selecting multiple items in a list box by using the following code.

Set db = CurrentDb()
Set rs1 = db.OpenRecordset("Usage", dbOpenDynaset, dbAppendOnly)



Set ctl = [Forms]![frmsearch]![lstSelector]
For Each varItem In ctl.ItemsSelected
rs1.AddNew
rs1!ID = ctl.ItemData(varItem)
rs1!UsageDate = Me.txtDate
rs1!PlanReturnDate = Me.txtplanReturn
rs1!District = Me.lstDistrict
rs1!Notes = Me.txtnotes
rs1.Update

what I need to do now, is to loop(I think) through and amend all the records in a populate listbox, with no selections, similar to above, but without selection.

would really appreciate any help you could give.

thanks in advance
 

JHB

Have been here a while
Local time
Today, 06:24
Joined
Jun 17, 2012
Messages
7,732
Can't you just replace the ItemsSelected with the ListCount?
 

cocowomble

Registered User.
Local time
Yesterday, 21:24
Joined
May 25, 2014
Messages
25
Can't you just replace the ItemsSelected with the ListCount?

would I still need
For Each varItem In ctl.listcount
.....
next

??
 

Cronk

Registered User.
Local time
Today, 14:24
Joined
Jul 4, 2013
Messages
2,774
If you want to do stuff with the rows which are NOT selected
Code:
for intRow = 0 To ctlSource.ListCount - 1 
   if not ctlSource.selected(intRow) then 
      'Do your edit stuff using ctlSource.Column(X, intRow) 
   end If 
next intRow
 

Users who are viewing this thread

Top Bottom