Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box 1

Status
Not open for further replies.

Ray1127

Programmer
Feb 22, 2002
231
US
I have the following code in an Access 2000 Form:

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
'Clear groups
*** For Each itm 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

The line above with the *** is giving me an error and nothing I've tried is correcting it. What I need to do is loop through all of the items in the combobox and if an item is in the Recordset the Selected property should be set to true. Any help would be appreciated.
 
You may try to replace this:
For Each itm In Me.Combo10
with this:
For itm = 0 To Me!Combo10.ListCount - 1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks.

Now I have a new issue The next line checks to see if the listbox item is = to the record. If it is it needs to set the Selected Property to true. the **** code below doesn't work. Is there a way in code to set the selected property for the item to true????

For intloop = 0 to Me.Combo10.listcount - 1
If Forms!frmJOMReports.Combo10.ItemData(intloop) = rsgp!group Then
**** Forms!frmJOMReports.Combo10.ItemData (intloop).Selected = True
End If

Next intloop
 
Me!Combo10.Selected(intloop) = True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top