M
Mark Taimanov
I have a form with a combo box, cboCategories and a multi-
select list box (extended), cboSubCategories.
User selects a category from cboCategories which then
limits the list box with the relevant subCategories. I
want to achieve a report which pulls the subcategories
relating to the selected category.
So if for example it was a car database - category might
be Ford, and subcategories might be green and red.
The code I used was based on Microsoft Knowledge Base
Article - 135546 as follows :
Private Sub Command6_Click()
Dim Q As QueryDef, DB As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
Dim Itm2 As Variant
Dim control2 As Control
Dim Criteria2 As String
'Prints Report
' Build a list of the selections.
Set ctl = Me![cboSubCategories]
Set control2 = Me![cboCategories]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData
(Itm) _
& Chr(34)
End If
Next Itm
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in
the" & _
" list box!", 0, "No Selection Made")
Exit Sub
End If
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("DMA Photo Library Query")
Q.SQL = "Select * From [DMA Photo Library] Where
[subCategoryName] In(" & Criteria & _
")AND [Category] = Me!cboCategories ;"
Q.Close
' Run the query/report
DoCmd.OpenReport "DMA Photo Library", acViewPreview
End Sub
This works as desired but because the procedure is not
aware of what is in Me!cboCategories , it sees it as a
parameter. If I fill in the parameter prompt - I get what
I want.
Except = that is not what I want as I want it to happen
automatically.
A little lost and guidance would be much appreciated.
Many thanks
Mark
select list box (extended), cboSubCategories.
User selects a category from cboCategories which then
limits the list box with the relevant subCategories. I
want to achieve a report which pulls the subcategories
relating to the selected category.
So if for example it was a car database - category might
be Ford, and subcategories might be green and red.
The code I used was based on Microsoft Knowledge Base
Article - 135546 as follows :
Private Sub Command6_Click()
Dim Q As QueryDef, DB As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
Dim Itm2 As Variant
Dim control2 As Control
Dim Criteria2 As String
'Prints Report
' Build a list of the selections.
Set ctl = Me![cboSubCategories]
Set control2 = Me![cboCategories]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData
(Itm) _
& Chr(34)
End If
Next Itm
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in
the" & _
" list box!", 0, "No Selection Made")
Exit Sub
End If
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("DMA Photo Library Query")
Q.SQL = "Select * From [DMA Photo Library] Where
[subCategoryName] In(" & Criteria & _
")AND [Category] = Me!cboCategories ;"
Q.Close
' Run the query/report
DoCmd.OpenReport "DMA Photo Library", acViewPreview
End Sub
This works as desired but because the procedure is not
aware of what is in Me!cboCategories , it sees it as a
parameter. If I fill in the parameter prompt - I get what
I want.
Except = that is not what I want as I want it to happen
automatically.
A little lost and guidance would be much appreciated.
Many thanks
Mark