Opening Reports for Selected Items in List Box

A

alianzista84

As the subject line describes, I'm having trouble doing that. Eve
though I select many items in the list box, only the item that i
highest in the list box gets itsinformation displayed on the report
How do I make so that all the selected items in the list box ge
their proper information displayed on the report

Thanks

P.S. This is a snippet of the code I have for the display repor
button..

Private Sub PrintButton_Click(
Const RName = "rptByApp
Const RName2 = "rptBySvr
Const RName3 = "rptByDB

Dim ProjName, WClause, Proj, c As Contro

Set c = Me!lboProjec
Select Case Me!optSelectionTyp
Case 1 ' Application
Select Case Me!optIssueStatu
Case 1 ' ALL ISSUE
Me!NowPrinting.Visible = Tru
For Each ProjName In c.ItemsSelecte
Me![NowPrinting].Caption = "Now Printin
Selection(s)
WClause = "[DateOpened] Between #" &
Me![Start] & "# AND #" &
Me![End] & "# AND [Phase] = '"

c.ItemData(ProjName) & "'
DoCmd.OpenReport
ReportName:=RName,
WhereCondition:=WClause,
view:=Me![OutputTo
ProjName = ProjName +
Next ProjNam
 
V

Van T. Dinh

It looks to me that you are opening the same Report with different
(filtered) DataSource for each iteration of the loop. This way, each loop
will simply refresh the same Report with new data. Hence, only the
"highest" item from the ListBox is displayed since this is the last
iteration.

If you want one Report displaying data related to the Items selected in the
ListBox, you need to construct the WClause using the method in The Access
Web article:

http://www.mvps.org/access/forms/frm0007.htm
 
A

alianzista84

Dim ProjName, WClause, Proj, c As Contro
Dim varItem As Varian
Dim strSQL As Strin

Set c = Me!lboProjec
Select Case Me!optSelectionTyp
Case 1 ' Application
Select Case Me!optIssueStatu
Case 1 ' ALL ISSUE
Me!NowPrinting.Visible = Tru
' strSQL = "Select * from qryDaysToResolve wher
[Phase]=

strSQL = "Select * from qryDaysToResolve wher
[Phase]=
'Assuming long [EmpID] is the bound field in l
'enumerate selected items an
'concatenate to strSQ
For Each varItem In c.ItemsSelecte
strSQL = strSQL & c.ItemData(varItem)
" OR [Phase]=
'Next varIte
'Trim the end of strSQ
strSQL = Left$(strSQL, Len(strSQL) - 12



DoCmd.OpenReport
ReportName:=RName,
WhereCondition:=strSQL,
view:=Me![OutputTo
varItem = varItem +
Next varIte

I'm not sure how about to go implementing that code from the link yo
posted...I tried my best as what's pasted above but I'm still no
sure how to get the results I want....Thank
 
V

Van T. Dinh

The article constructs an SQL String for a *Select* Query.

In your case, you only want to construct the string for the "wherecondition"
of the OpenReport Method. The "wherecondition" string is just the criteria
(WHERE) clause without the word "WHERE". Hence, instead of starting the SQL
construction with:

strSQL = "Select * from qryDaysToResolve where [Phase]="

try simply:

strSQL = "[Phase]="
 

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