Code refuses to loop through records

twoplustwo

Registered User.
Local time
Today, 09:39
Joined
Oct 31, 2007
Messages
507
Hi all,

I have a list box filtered and displayed on a form.

Against each company there can be a number of sites. I need my code to loop through each instance where the companyID of the company selected passes each site to a string that will then be used in an email.

The emailing part is fine, I'm just struggling to list each site in the data set.

Example table:

Customer Site
A 1
A 2
A 3

I need to pass sites 1,2 and 3 to a string but I'm stuck!

Thanks for any suggestions.
 
Simple Software Solutions

Code:
For X = 0 to listbox.listcount -1

   If listbox.Selected(x) = True Then
      code here.
      Answer = Answer & listbox.column(1,x)
   Endif
Next

CodeMaster::cool:
 
or alternatively, if you select item(s) in the listbox then

for each item in listbox.selecteditems
... etc
next

but getting the syntax accurate to access each item correctly is not immediately obvious
 
Hi guys,

I'm not sure which variables are being passed to the bolded sections:

For X = 0 to listbox.listcount -1

If listbox.Selected(x) = True Then
code here.
Answer = Answer & listbox.column(1,x)
Endif
Next
 
For x = 0 To lstCompanies.ListCount - 1
If lstCompanies.Selected(x) = True Then
strSite = strSite & lstCompanies.Column(2, x)
End If
Next

I have the above sorted.

Buttttttt...

It's not returning the list of sites that I need.

To be specific, it only returns the highlighted site - I kinda need all sites against thjat company passed to the string :)
 
Last edited:
I have used similar code to try and select a number of fields, but for some reason, the selected field is not picked up, i.e. the loop is never entered, as if nothing was selected. This is my code:

Dim vntIndex As Variant
'Loop through each item selected in the list box,
'storing codes and names which are selected
For Each vntIndex In Me.lstMRINames.ItemsSelected
Me.lstMRINames.BoundColumn = 1
Me.MRINames = Me.MRINames & Me.lstMRINames.ItemData(vntIndex) & " "
Me.lstMRINames.BoundColumn = 2
Me.MRINames = Me.MRINames & Me.lstMRINames.ItemData(vntIndex) & " "
Next vntIndex

Does anyone have any ideas? Is it to do with the fact that I am a bound control?
 

Users who are viewing this thread

Back
Top Bottom