"Geir Baardsen" <ge***********@hotmail.com> wrote
From a listbox I'd like to send only selected items to a report.
You haven't explained completely what you intend to do, but if I understand
correctly, you will have a listbox that has as its rowsource an SQL query
that brings together several tables; your listbox is a multi-select listbox,
and you want to make multiple selections; you want to print the select
records, which are rows from your listbox.
If the above is correct, one way to do this would be to use your original
SELECT query to fill a table - I'll call it qryFillTable.
a. Create the table with the fields you want from your query. You can also
create a "Make Table" query out of your original query using the Query
Designer to do the work automtically. I'll call it tblListBox.
b. Add a field to the end of the table, a yes/no field, "Selected"
c. Change the rowsource of the listbox to the table name
d. When you open your form, run three statements:
DoCmd.RunSQL "DELETE * FROM tblListBox"
DoCmd.RunSQL "INSERT INTO tblListbox SELECT * FROM qryFillTable"
myListBox.Requery
Your listbox is now filled with your query, plus you have an "extra" field
in your table, 'Selected'. Each time that you select a row in the listbox,
set the selected field to True. When you are ready to print your report,
use as your recordsource "SELECT * FROM tblListBox WHERE Selected=True"
Darryl Kerkeslager