I am trying to get this to work but I cannot figure it out.
At this point I'm getting an object required error on the docmd.openreport line. I'm sure its because I don't have the where clause set up properly. If I debug strwhere it has the data for the where clause. The table has an id field and a category field. I want to limit based on the category. The report is based on a query of all records in the vol_request_table. Here is the SQL for the query behind the report
SELECT Members_Table.Member_Id AS Members_Table_Member_Id, Members_Table.First_Name, Members_Table.Last_Name, Volunteer_Categories_Table.Volunteer_Category_Id AS Volunteer_Categories_Table_Volunteer_Category_Id, Volunteer_Categories_Table.Volunteer_Category, Volunteer_Request_Table.Member_Id AS Volunteer_Request_Table_Member_Id, Volunteer_Request_Table.Volunteer_Category_Id AS Volunteer_Request_Table_Volunteer_Category_Id, Volunteer_Request_Table.Comments
FROM Volunteer_Categories_Table INNER JOIN (Members_Table INNER JOIN Volunteer_Request_Table ON Members_Table.[Member_Id] = Volunteer_Request_Table.[Member_Id]) ON Volunteer_Categories_Table.[Volunteer_Category_Id] = Volunteer_Request_Table.[Volunteer_Category_Id];
This is the event procedure.
Private Sub RunReport_Click()
On Error GoTo Err_RunReport_Click
Dim strWhere As String
Dim ctl As Control
Dim varItem As Variant
'make sure a selection has been made
If Me.VolCatSel.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 category"
Exit Sub
End If
'add selected values to string
Set ctl = Me.VolCatSel
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
'open the report, restricted to the selected items
DoCmd.OpenReport "Volunteer_Requests_Report", acPreview, , ((Volunteer_Categories_Table.Volunteer_Category) = (" & strWhere & "))
Exit_RunReport_Click:
Exit Sub
Err_RunReport_Click:
MsgBox Err.Description
Resume Exit_RunReport_Click
End Sub
At this point I'm getting an object required error on the docmd.openreport line. I'm sure its because I don't have the where clause set up properly. If I debug strwhere it has the data for the where clause. The table has an id field and a category field. I want to limit based on the category. The report is based on a query of all records in the vol_request_table. Here is the SQL for the query behind the report
SELECT Members_Table.Member_Id AS Members_Table_Member_Id, Members_Table.First_Name, Members_Table.Last_Name, Volunteer_Categories_Table.Volunteer_Category_Id AS Volunteer_Categories_Table_Volunteer_Category_Id, Volunteer_Categories_Table.Volunteer_Category, Volunteer_Request_Table.Member_Id AS Volunteer_Request_Table_Member_Id, Volunteer_Request_Table.Volunteer_Category_Id AS Volunteer_Request_Table_Volunteer_Category_Id, Volunteer_Request_Table.Comments
FROM Volunteer_Categories_Table INNER JOIN (Members_Table INNER JOIN Volunteer_Request_Table ON Members_Table.[Member_Id] = Volunteer_Request_Table.[Member_Id]) ON Volunteer_Categories_Table.[Volunteer_Category_Id] = Volunteer_Request_Table.[Volunteer_Category_Id];
This is the event procedure.
Private Sub RunReport_Click()
On Error GoTo Err_RunReport_Click
Dim strWhere As String
Dim ctl As Control
Dim varItem As Variant
'make sure a selection has been made
If Me.VolCatSel.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 category"
Exit Sub
End If
'add selected values to string
Set ctl = Me.VolCatSel
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
'open the report, restricted to the selected items
DoCmd.OpenReport "Volunteer_Requests_Report", acPreview, , ((Volunteer_Categories_Table.Volunteer_Category) = (" & strWhere & "))
Exit_RunReport_Click:
Exit Sub
Err_RunReport_Click:
MsgBox Err.Description
Resume Exit_RunReport_Click
End Sub