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!

How do you add to a listbox on report?

Status
Not open for further replies.

Culby

Technical User
Dec 9, 2001
13
US
I need to take selected items from a mult-Select listbox on a FORM and display them on a REPORT. I can get the selected items to print to the debug screen but listboxes or textboxes don't have the same funtionality on reports that they do on forms so I'm having trouble getting the information to display on a report.

Currently, I'm having some success using the caption of a lable to display the results by looping through the list and adding the additional selected items to the caption of the label on the report.

Isn't there a more direct way to display data that needs to by dynamically derived as the report opens? Any ideas would be helpful. [neutral] ? [neutral] ? [neutral] ?

Thanks,
Culby
 

Any data displayed in a report has either come from a recordset or be some calculated derivation from a recordset.

And a recordset's data originates in a table.

So I suspect that when you make your list box selection, you are not appending them to a table, hence they are not "seen" by a report.

What you can do is set up a table to serve as a repository for the list box selected values. Add a VBA embedded DELETE SQL statement to clear the table at some desired point in time.

Cheers, Bill
 
a report's text boxes can also be made to reference data in controls on a form. For a list box you just set the Control Source to something like [Forms]![Form1]![ListBox1]. This sets the contents of the text box to the value in the bound column of the selected item in the list box.

Unfortunately I have never done this with multiple selected items so I am not exactly sure of how this is done. There is an ItemsSelected property which places the selected items into a collection, so it should be possible to loop through this collection and retrieve details of the selected items. Check Help for ItemsSelected.
Have fun! :eek:)

Alex Middleton
 
You can also use code within the report such as this:

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim t As Integer
If FormatCount = 1 Then
  For t = 0 To Forms!form1.Text0.ListCount
    If Forms!form1.Text0.Selected(t) Then
      Report.CurrentX = 0  'Straight column
      Report.Print Forms!form1.Text0.ItemData(t)
      Me.Detail.Height = Me.Detail.Height + Report.TextHeight(t)
    End If
  Next t
End If
End Sub

This can get tricky when printing multiple pages, but can also be quite useful at times.

For most cases a simple "temp" table as mentioned above is the best route.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top