Multi Select

A

AccessDB

I created a list box that will let me select more than one, but the
problem is that when I run the report (a command button that I created
and works) the results are not what I want. Instead of showing just
the particular items that I selected it shows everything.
Here is the code that I have for my list box.
Private Sub cmdCreateReport_Click()
On Error GoTo Err_cmdCreateReport_Click

Dim strCriteria As String
Dim bolCriteria As Boolean

bolCriteria = False
strSQL = ""
strCriteria = ""

BeginSQL


strCriteria = "WHERE ("
If Not IsNull(Me.cboMfg.Value) Then
strCriteria = strCriteria & "(([new].[MANUFACTURER]) = '" &
cboMfg.Value & "') "
bolCriteria = True
End If

If Not IsNull(Me.ListApp.Value) Then
If Not bolCriteria Then
strCriteria = strCriteria & "(([new].[APPLICATION]) = '" &
ListApp.Value & "') "
Else
strCriteria = strCriteria & "AND (([new].[APPLICATION]) =
'" & ListApp.Value & "') "
End If
bolCriteria = True
End If

If bolCriteria Then
'if criteria was entered add it to the SQL string
strSQL = strSQL & strCriteria & ")"
End If

'close SQL and create query
EndSQL

ShowReport 'Me.cboSortBy1.Value, Me.cboSortBy2.Value

Exit_cmdCreateReport_Click:
Exit Sub

Err_cmdCreateReport_Click:
MsgBox Err.Description
Resume Exit_cmdCreateReport_Click

End Sub
 
A

AccessDB

See my sample database. It shows code for how to loop through a multiselect
listbox to get the values:

Building SQL string based on values entered into controls
 http://www.accessmvp.com/KDSnell/SampleDBs.htm#FilterForm

--

        Ken Snell
<MS ACCESS MVP>http://www.accessmvp.com/KDSnell/




I created a list box that will let me select more than one, but the
problem is that when I run the report (a command button that I created
and works) the results are not what I want. Instead of showing just
the particular items that I selected it shows everything.
Here is the code that I have for my list box.
Private Sub cmdCreateReport_Click()
On Error GoTo Err_cmdCreateReport_Click
   Dim strCriteria As String
   Dim bolCriteria As Boolean
   bolCriteria = False
   strSQL = ""
   strCriteria = ""
   BeginSQL
   strCriteria = "WHERE ("
   If Not IsNull(Me.cboMfg.Value) Then
       strCriteria = strCriteria & "(([new].[MANUFACTURER]) = '" &
cboMfg.Value & "') "
       bolCriteria = True
   End If
   If Not IsNull(Me.ListApp.Value) Then
           If Not bolCriteria Then
           strCriteria = strCriteria & "(([new].[APPLICATION]) = '" &
ListApp.Value & "') "
           Else
           strCriteria = strCriteria & "AND (([new].[APPLICATION]) =
'" & ListApp.Value & "') "
       End If
       bolCriteria = True
   End If
   If bolCriteria Then
   'if criteria was entered add it to the SQL string
       strSQL = strSQL & strCriteria & ")"
   End If
   'close SQL and create query
   EndSQL
   ShowReport 'Me.cboSortBy1.Value, Me.cboSortBy2.Value
Exit_cmdCreateReport_Click:
   Exit Sub
Err_cmdCreateReport_Click:
   MsgBox Err.Description
   Resume Exit_cmdCreateReport_Click
End Sub- Hide quoted text -

- Show quoted text -

Which one? You have 6 categories and about 1 to 3 different zip files
in each one.
Thank you.
 
A

AccessDB

See my sample database. It shows code for how to loop through a multiselect
listbox to get the values:
Building SQL string based on values entered into controls
 http://www.accessmvp.com/KDSnell/SampleDBs.htm#FilterForm

        Ken Snell
<MS ACCESS MVP>http://www.accessmvp.com/KDSnell/
news:0c525034-5102-484d-b19a-5287cefeeb21@v17g2000vbb.googlegroups.com....
I created a list box that will let me select more than one, but the
problem is that when I run the report (a command button that I created
and works) the results are not what I want. Instead of showing just
the particular items that I selected it shows everything.
Here is the code that I have for my list box.
Private Sub cmdCreateReport_Click()
On Error GoTo Err_cmdCreateReport_Click
   Dim strCriteria As String
   Dim bolCriteria As Boolean
   bolCriteria = False
   strSQL = ""
   strCriteria = ""
   BeginSQL
   strCriteria = "WHERE ("
   If Not IsNull(Me.cboMfg.Value) Then
       strCriteria = strCriteria & "(([new].[MANUFACTURER])= '" &
cboMfg.Value & "') "
       bolCriteria = True
   End If
   If Not IsNull(Me.ListApp.Value) Then
           If Not bolCriteria Then
           strCriteria = strCriteria & "(([new].[APPLICATION]) = '" &
ListApp.Value & "') "
           Else
           strCriteria = strCriteria & "AND (([new].[APPLICATION]) =
'" & ListApp.Value & "') "
       End If
       bolCriteria = True
   End If
   If bolCriteria Then
   'if criteria was entered add it to the SQL string
       strSQL = strSQL & strCriteria & ")"
   End If
   'close SQL and create query
   EndSQL
   ShowReport 'Me.cboSortBy1.Value, Me.cboSortBy2.Value
Exit_cmdCreateReport_Click:
   Exit Sub
Err_cmdCreateReport_Click:
   MsgBox Err.Description
   Resume Exit_cmdCreateReport_Click
End Sub- Hide quoted text -
- Show quoted text -

Which one? You have 6 categories and about 1 to 3 different zip files
in each one.
Thank you.- Hide quoted text -

- Show quoted text -

I think I found it. Based on what you have, I should be able to get
the code that I wnat and need. Thank you very much.
 

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