Iteration through a multi-Select List box

  • Thread starter RayMilhon via AccessMonster.com
  • Start date
R

RayMilhon via AccessMonster.com

I have the following code in a form:

Private Sub cmdQuarterly_Click()
Dim strsql As String, oldipa As String, itm As Variant
Dim rs As New ADODB.Recordset, rsgp As New ADODB.Recordset
strsql = "Select ipa from tbl_mailing_groups group by ipa"
If Not IsNull(Me.txtGroupid) Then oldipa = Me.txtGroupid
rs.Open strsql, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly
Do Until rs.EOF
Me.txtGroupid = rs!ipa
Me.Combo10.Requery
strsql = "Select group from tbl_mailing_groups " & _
"Where ipa = """ & rs!ipa & """ Group By group"
rsgp.Open strsql, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly
Do Until rsgp.EOF
for each item in me.combo10
If Forms!frmJOMReports.Combo10.ItemData(itm) = rsgp!group
Then
Forms!frmJOMReports.Combo10.ItemData(itm).Selected = True
End If
Next itm
rsgp.MoveNext
Loop
Call cmdPreviewScoreReport_Click
rs.MoveNext
Loop


End Sub

The form is normally used to generate 5 reports based on the group and
subgroups. The code addes is to automate the report quarterly for several
groups. I have a table that contains the groups and subgroups for each
quarterly report and I need to go through those to set the controls on the
form and generate the reports. The problem I'm having is in errors on the
for each routine. I need to iterate through each item in the listbox and if
the item is in the recordset for the grouop set the selected property to true.


I've tried everything I can think of and it errors on that line everytime.
I've tried:
for each item in me.combo10
for each item in me.combo10.listitems
for each item in me.combo10.itemdata

What am I missing?????
 
P

PieterLinden via AccessMonster.com

Is it a combobox or a ListBox?

Dim varItem as Variant
For Each varItem in me.lbxTest.ItemsSelected
Debug.print me.lbxtest.ItemData(varItem)
Next varItem
 
R

RayMilhon via AccessMonster.com

It started as a combobox but requirements changed where multiple items were
possible so I changed it to a listbox. However due to all of the code that
had been written behind the form I left the name as it was.
Is it a combobox or a ListBox?

Dim varItem as Variant
For Each varItem in me.lbxTest.ItemsSelected
Debug.print me.lbxtest.ItemData(varItem)
Next varItem
I have the following code in a form:
[quoted text clipped - 43 lines]
What am I missing?????
 

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