how to refer to all rows in a list box

A

Access infant

Hai,
I have a form in which there's a list box and two command buttons
1. cmdPrepareReport for selected
2. cmdPrepareReport for all
for the first command button i used the following code
For Each varItem In Me!lstCName.ItemsSelected
' Grab the ContactID column for each selected item
strWhere = strWhere & Me!lstCName.Column(0, varItem) & ","
' the last comma will be removed later
Next varItem
This strWhere will be later passed to the report as criteria
If the second button is selected, I must grab the contactId of all records
in the rowsource. can any one tell me how to do this?
 
D

Dirk Goldgar

Access infant said:
Hai,
I have a form in which there's a list box and two command buttons
1. cmdPrepareReport for selected
2. cmdPrepareReport for all
for the first command button i used the following code
For Each varItem In Me!lstCName.ItemsSelected
' Grab the ContactID column for each selected item
strWhere = strWhere & Me!lstCName.Column(0, varItem) & ","
' the last comma will be removed later
Next varItem
This strWhere will be later passed to the report as criteria
If the second button is selected, I must grab the contactId of all records
in the rowsource. can any one tell me how to do this?


An easier way to do this, rather than create a string that lists all the
items in the list box, is just to leave the where-criteria string empty if
there are no critereria to be applied.

If you really want to build a full list of the items in the list box, then
you can do it like this:

Dim i As Long

With Me!lstCName
For i = Abs(.ColumnHeads) To (.ListCount - 1)
' Grab the ContactID column for each item
strWhere = strWhere & .Column(0, i) & ","
' the last comma will be removed later
Next i
End With
 

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