HELP really needed to change combo box to list box for multi selec

A

Alan

I have this code for my combo that select the value inside and return it to
the report

If Nz(Me.lstReportFilter) <> "" Then
strReportFilter = "([SalesGroupingField] = """ & Me.lstReportFilter &
""")"
End If

what i need is a lost box so that i can select multi values in the box

I have this below but it doesn't reckonise the strings Please can any one
help

strReportFilter = strReportFilter & ",'" &
Me.lstReportFilter.ItemData(varitem) _
& "'"
Next varitem
If Nz(Me.lstReportFilter) <> "" Then
strReportFilter = "([SalesGroupingField] = """ & Me.lstReportFilter &
""")"
End If
 
A

Argyronet

Hi,

Here is an example :

Private Sub cmdGetFilter_Click()
Dim strFilter As String
strFilter = GetFilter()
If Len(strFilter) Then
MsgBox strFilter
End If
DoCmd.OpenReport , , , "[SalesGroupingField] IN (" & strFilter & ")"
End Sub

Private Function GetFilter() As String
On Error GoTo cmdGetFilter_Click_Error
With lstReportFilter
For I = 0 To lstReportFilter.ListCount - 1
If .Selected(I) Then
''' Change if .ItemData is string => & "'" & ItemData(I)
& "', "
strCriteria = strCriteria & .ItemData(I) & ", "
End If
Next
strCriteria = Left$(strCriteria, Len(strCriteria) - 2)
End With
On Error GoTo 0
GetFilter = strCriteria
cmdGetFilter_Click_Exit:
Exit Function

cmdGetFilter_Click_Error:
If Err = 94 Then
MsgBox "You must select one or more items to continue !", 48, "Item
required"
Else
MsgBox Err.Description, 48, "Error " & Err.Number
End If
GetFilter = ""
Resume cmdGetFilter_Click_Exit
End Function

P.S. You must define Multi select property in design mode.
--
Argy
Goto : http://argyronet.developpez.com/
Livres :
Créez des programmes avec Microsoft Access 2007 (ISBN 2742982442)
VBA pour Office 2007 (ISBN 2742983910)
 

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