From: Access infant on
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?
--
from
chanakya
Baruva
From: Dirk Goldgar on
"Access infant" <Accessinfant(a)discussions.microsoft.com> wrote in message
news:8B1B64F0-1EDF-4E5D-87C4-20D33A010F93(a)microsoft.com...
> 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?
> --
> from
> chanakya
> Baruva


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


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

From: Access infant on
Thanks a lot. This is exactly what i wanted
--
from
chanakya
Baruva