Code for Listbox

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

I found the property control that will allow me to select several rows of
records within my list box. I would like those selected records to print out
on a report. How do I distinguish between those that are selected and those
that
are not and have them print out on a report along with other records that
appear on my form? Thanks
 
On Wed, 23 Jan 2008 04:54:02 -0800, Sean

You would have to write a bit of code. There is no data binding to a
multi-select listbox.
For example in your Report_Open event you could get a comma-separated
list of the ID values of the selected items by looping over the items
and checking the Selected property. There is an example in the help
file.
With that string, you can create a dynamic query:
sql = "select * from MyReportQuery
where MyIDField in (" & myString & ")"
This would limit your report query to only those IDs listed in your
comma-separated string.
Last step is to assign this string, still in the Report_Open event:
Me.RecordSource = sql

-Tom.
 
Would it be easier once all items are selected on the form to append them to
a temp table and then draw the report from there? Is the code then easier to
do this and do you have an example if so?
 
No: you will still have to loop through the ItemsSelected of the list box to
append them to your temp table.
 
Back
Top