Tricky Listbox Loop

  • Thread starter Thread starter CondtllyFrmttd
  • Start date Start date
C

CondtllyFrmttd

Hey Everyone.
I have a complicated situation. Lets say that I have 2 rows in my list
box:
[ID].[2006-145] [Category].[1]
[ID].[2006-145] [Category].[2].

The ID numbers are the same but the Category numbers are different. My
next row in the ListBox may say:

[ID].[2006-146] [Category] .[1].

I am trying to create a button that would loop through the listbox and
create emails one at a time containing the information about each ID.

I have already tried things in the nature of:

Dim I As Integer
For I = 0 To lstBoxName.listcount
Next I

I cannot finish this problem!!! Anyone have any ideas? THanks
 
As long as your ID's are sorted, (or as long as all duplicates appear
together as a group) this aircode may help:

I changed your Capital I to r because I avoid using I and l (small case L)
by themselves as variables since its so easy to confuse those with the
number 1 when reading/debugging (and also because I like the clarity of
using r for row...). Strictly a personal preference, feel free to do as you
wish :-)

Dim r As Integer
Dim strTemp as String

For r = 0 To lstBoxName.ListCount -1
If strTemp <> lstBoxName.Column(0, r) then
' ID has changed. Update strTemp and send an email for this ID
strTemp = lstBoxName.Columns(0, r)
...add your code to send email
Else
' Ignore: ID is unchanged from previous item (this is a duplicate
ID)
End If
Next r

HTH,
 
Back
Top