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!

How to use a form to select multiple criteria in order to print previe

Status
Not open for further replies.

Jorgandr

Programmer
May 10, 2002
58
US
I have a form that has a list box on it then when they select a name and click on my print preview button they will get a report listing only that person. How do you code it so I can make the list box a multiple selection? I assuming it has to deal with arrays and a do while loop? I'm not too sure about the syntax in access for arrays though. Any help would be appreciated thank you
 
The Properties of the list box has the multi-selection
Open the form in design view
Double click the listbox to bring up properties
look for "Multi Select" property
there are 3 choices
None
Simple
Extended

I use Simple

The code to find the selected ones is this
Private Sub Report_Open(Cancel As Integer)
Dim A As Integer, SQL, Criteria As String
Dim ctlList As Control, varItem As Variant
SQL = "Select * From [yourTable] Where yourField = "
' Return Control object variable pointing to list box.
Set ctlList = Forms!form3!List2
' Enumerate through selected items.
For Each varItem In ctlList.ItemsSelected
' Print value of bound column.
Debug.Print ctlList.ItemData(varItem)
Criteria = Criteria & "'" & ctlList.ItemData(varItem) & "' OR "
Next varItem
Criteria = Left(Criteria, Len(Criteria) - 4)
SQL = SQL & Criteria & ";"
Me.RecordSource = SQL

End Sub

Now you need to put this code in the reports On-Open event



DougP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top