I have a form with a listbox that gets categories from a table. based on which categories were selected (multiselect), a recordset is built from another table. But now that i have a recordset floating around in RAM, how the heck do i spit the data out?
I want to use that recordset to populate a Report I have made. how!?
heres what i have:
Listbox (multiselect)
button to click and fire off this code piece
My original problem was i tried building a query, but I couldnt get the criteria to work correctly.
I needed to put inside the CAT_ID Criteria field, a IN (Forms![Report - Category]![Text18])
In this case text18 = "7,3,8" (or some combination of IDs)
for some reason the query would pull nothing unless text18 had only 1 item in it....
leading me to the above VB attempts to do the same thing
HELP!
I want to use that recordset to populate a Report I have made. how!?
heres what i have:
Listbox (multiselect)
button to click and fire off this code piece
Code:
[COLOR="YellowGreen"]' Set query string[/COLOR]
strSQL = "SELECT categories.category, [Public programs contacts].[Last Name], " & _
"[Public programs contacts].[First name], [Public programs contacts].Cat_ID " & _
"FROM categories INNER JOIN [Public programs contacts] ON categories.ID=[Public programs contacts].Cat_ID " & _
"WHERE cat_id IN "
[COLOR="YellowGreen"]' init working criteria[/COLOR]
strSQL2 = ""
[COLOR="yellowgreen"]'Loop to build ID list[/COLOR]
If Me!box_category_list.ItemsSelected.Count > 0 Then
For Each varItem In Me!box_category_list.ItemsSelected
strSQL2 = strSQL2 & Me!box_category_list.ItemData(varItem) & ","
Next varItem
strSQL2 = strSQL & "(" & Left(strSQL2, Len(strSQL2) - 1) & ");"
[COLOR="yellowgreen"]'Recordset[/COLOR]
Dim db As DAO.Database, rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL2)
While Not rs.EOF
Debug.Print rs.Fields(0)
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
[COLOR="yellowgreen"]'somehow call this report and use data from above recordset[/COLOR]
DoCmd.OpenReport "My_Report"
My original problem was i tried building a query, but I couldnt get the criteria to work correctly.
I needed to put inside the CAT_ID Criteria field, a IN (Forms![Report - Category]![Text18])
In this case text18 = "7,3,8" (or some combination of IDs)
for some reason the query would pull nothing unless text18 had only 1 item in it....
leading me to the above VB attempts to do the same thing
HELP!
Last edited: