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

Use a listbox to prompt for report criteria

Status
Not open for further replies.
Apr 19, 2000
73
US
Access2000. Need to create an unbound form that prompts for report criteria that the user will select from a list box. I know how to create a form that prompts for report criteria using an unbound text box but I want the user to be able to select multiple items from a list box instead. Thanks.
 
I don't see a question here but I'll assume you need to build a &quot;WHERE&quot; condition for your report.<br><br>Listbox is lbxList.&nbsp;&nbsp;Contains strings (not numbers).<br>Button to generate report is &quot;cmdGo&quot;.<br>Field to select is called Field1.<br>Report is called &quot;rptTest&quot;...<br><br>Sub cmdGo_Click<br><br>Dim i As Integer<br>Dim strFilter As String<br><br>' Generate list of selected items<br>For i = 0 To lbxList.ListCount - 1<br>&nbsp;&nbsp;&nbsp;&nbsp;If lbxList.Selected(i) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strFilter = strFilter & &quot;<font color=red><b>'</b></font>&quot; & lbxList.Column(0, i) & &quot;<font color=red><b>'</b></font>,&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>Next i<br><br>'&nbsp;&nbsp;Truncate trailing comma<br>If Len(strFilter) &gt; 0 Then strFilter = Left$(strFilter, Len(strFilter) - 1)<br><br>DoCmd.OpenReport &quot;rptTest&quot;,,,&quot;Field1 IN (&quot; & strFilter & &quot;)&quot;<br><br>End Sub<br> <p>Jim Conrad<br><a href=mailto:jconrad3@visteon.com>jconrad3@visteon.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top