Selecting an Item in a list box

  • Thread starter Thread starter Chad
  • Start date Start date
C

Chad

What would be the syntax to select the next item in a
list box. Example:

ListBox1 contains the following information:
ALABAMA
ALASKA
ARIZONA
ARKANSAS

What would I need to do to cycle through the contents of
the list box, selecting each record as I go through. I
know that I need to use a loop but I just don't kow what
to put inside of it to be able to actually select each
record.

*********************************************************

For intIndex = 0 to ListBox1.ListCount - 1
'Select the next item in the list box
Next intIndex

*********************************************************

Thanks in advance
Chad
 
Hi,
For intIndex = 0 to ListBox1.ListCount - 1
ListBox1.Selected(intIndex) = True
Next intIndex
 
Dan,
Thanks a lot, your code allowed me to select each item
in the list box, unfortunately it didn't accomplish what
I needed it to.

I will use the example that I did previously.

In addition to that list box I have a Records check box
and a Pending check box that returns values based on
which record is selected in ListBox1. Unfortunately they
do not return values if you select the items through code
(like you showed me how to do). Is there any way to go
through the records of the list box and also have the
Record and Pending check boxes return values? Sorry if
this is vague, I will post my code so far:

**********************************************************
For intIndex = 0 To ListBox1.ListCount - 1
ListBox1.Selected(intIndex) = True
If intIndex = 0 Then
Forms!frmReports!cboSC1 = ListBox1.ItemData(intIndex)
Call UpdatecboSC1
If chkRecord = True Then
Forms!frmReports!optSC1Y = True
ElseIf chkPending = True Then
Forms!frmReports!optSC1P = True
Else
Forms!frmReports!optSC1N = True
End If
ElseIf intIndex = 1 Then
Forms!frmReports!cboSC2 = ListBox1.ItemData(intIndex)
Call UpdatecboSC2
If chkRecord = True Then
Forms!frmReports!optSC2Y = True
ElseIf chkPending = True Then
Forms!frmReports!optSC2P = True
Else
Forms!frmReports!optSC2N = True
End If
ElseIf intIndex = 2 Then
Forms!frmReports!cboSC3 = ListBox1.ItemData(intIndex)
Call UpdatecboSC3
If chkRecord = True Then
Forms!frmReports!optSC3Y = True
ElseIf chkPending = True Then
Forms!frmReports!optSC3P = True
Else
Forms!frmReports!optSC3N = True
End If
ElseIf intIndex = 3 Then
Forms!frmReports!cboSC4 = ListBox1.ItemData(intIndex)
Call UpdatecboSC4
If chkRecord = True Then
Forms!frmReports!optSC4Y = True
ElseIf chkPending = True Then
Forms!frmReports!optSC4P = True
Else
Forms!frmReports!optSC4N = True
End If
End If
DoEvents
Next intIndex
**********************************************************

When I run this chkRecord and chkPending never change
whereas if you click on the records in the liust box they
will.

Thanks again for all of your help,
Chad
 
Back
Top