List box

G

Guest

Hi
I’ve got search form (frmsearch) with a list box with several columns and
which has its Multi Select property set to “Extendedâ€. Is there a way the
user can select multiple rows from the list box and have it return the
resulting records to another form (frmMain)?
 
G

Guest

Add a button to the form with code along these lines in its Click event
procedure. For this example I've assumed the list box, lstEmployees, is of
employees and the list box's bound column is a numeric EmployeeID:

Dim varItem As Variant
Dim strEmployeeIDList As String
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.lstEmployees

If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected
strEmployeeIDList = strEmployeeIDList & "," &
ctrl.ItemData(varItem)
Next varItem

' remove leading comma
strEmployeeIDList = Mid(strEmployeeIDList, 2)

strCriteria = "[EmployeeID] In(" & strEmployeeIDList & ")"
DoCmd.OpenForm "frmMain", WhereCondition:=strCriteria
Else
MsgBox "No Employees Selected", vbInformation, "Warning"
End If

Ken Sheridan
Stafford, England
 

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

Top