Listbox

C

Carol Graham

How can I select from a listbox in a form and have my selections show up in
a report?
 
D

David Straker

Carol,
Do you mean "selection" or "selections" (plural)? Either way, first take a
look at DoCmd.OpenReport in VBA. The syntax is:
DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]The
"wherecondition" is really a filter string. If you use the Filter By Form
feature in Access, apply the filter and then switch to design view of the
form, you'll see the syntax of the filter string you've just created in the
Filter property of the form. It's on the Data Tab of the form's property
page. This will give you an example of how to build your own
"wherecondition" in VBA. Don't forget to delete the value in "Filter" when
you've finished or it gets stored with the form permanently.

The form has to have an Event Procedure behind a command button (e.g.
cmdPreview) that is coded something like:

Private Sub cmdPreview_Click()
DoCmd.OpenReport "myReportName", acViewPreview, ,
"((qryDxsTest.TestID=1))"
End Sub

My example shows a simple filter string where only one item is selected from
the listbox. If you want to support multiple selections from the listbox to
produce one report (personally I'd use a ListView with checkboxes), you'd
have to set the ListBox's Multi-Select property in the form designer and
then, in your cmdPreview_Click event handler, loop through the
ListBox.ItemsSelected collection in VBA.

Hope this helps. If you need more details, please ask.
David Straker
 

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

Similar Threads

Requery listbox 1
Submit form 0
Faster DCount or Query 6
Open Report with Criteria From Form 6
Open form 0
Deselecting items in a listbox 2
Listbox beforeupdate 2
Selecting Listbox items in code 2

Top