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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Contents of Listbox in a Report Header

Status
Not open for further replies.

kopy

Technical User
May 30, 2002
141
US
I have report that I want to use, in the header, the contents of a multi-select listbox on a form that is feeding the source query of the report.

Any ideas of how yo do this will be greatly appreciated.
Thanks, Kopy
 
You could write a function that you refer to in the report, that loops thru the ItemsSelected of the list box, builds a string and displays it on the Report.

You must already know how to loop thru the ItemsSelected since you are using that data in a query.

Code:
Function GetReportTitle()
dim strReportTitle as string
strReportTitle = ""

{Loop thru ItemsSelected building the string}

GetReportTitle = strReportTitle

Then in the header of the report put

=GetReportTitle()

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Ginger, thanks for the help. To be honest I think I will need a little help with the code to loop through the listbox and build the string.
Thanks, Kopy
 
I would probably modify the code used to create the criteria. Your existing code loops through the list box selected items. I expect this could be modified to get the results you need. Can you share your code?

Duane MS Access MVP
Now help me support United Cerebral Palsy
 
Function GetReportTitle()

Dim strReportTitle As String
Dim lbo As ListBox

strReportTitle = ""

Set lbo = Forms!frmPrint![ListLocation)]

For Each item In lbo.ItemsSelected
lbo.ItemData(item) = strReportTitle
Next

End Function
 
Code:
Function GetReportTitle() as String

Dim strReportTitle As String
Dim lbo As ListBox

strReportTitle = ""

    Set lbo = Forms!frmPrint![ListLocation)]
    
    For Each item In lbo.ItemsSelected
        strReportTitle = strReportTitle  & " - " & lbo.ItemData(item)
    Next
    If Len(strReportTitle) > 0 Then
        GetReportTitle = Mid(strReportTitle,4)
    End If
End Function

Duane MS Access MVP
Now help me support United Cerebral Palsy
 
Everyone, thank you very much!!!
 
or....


Function GetReportTitle() as String

Dim strReportTitle As String
Dim lbo As ListBox

strReportTitle = ""

Set lbo = Forms!frmPrint![ListLocation)]

For Each item In lbo.ItemsSelected
If len(strReportTitle) = 0 then
strReportTitle = lbo.ItemData(item)
Else
strReportTitle = strReportTitle & ", " & lbo.ItemData(item)
End If
Next

GetReportTitle = strReportTitle

End Function

But again I ask: aren't you already looping thru the ItemsSelected to build your report's Recordsource? This is just the same type of code...

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top