J
Jason
I have a form used to open a report and I need to set the RowSource of a
chart on the report based on a combo box on the form. The problem I'm having
is that if I try to set it before I open the form then I get an error that
the form is not open. If I try to do it after opening, then I get an error
that you can't set the RowSource after printing has begun.
I'm thinking I need to pass my SQL string to the report somehow and then use
it maybe in the OnOpen event? Here's the code I'm trying to use...
Private Sub cmdOpenrptMonthlyComparison_Click()
On Error GoTo Err_cmdOpenrptMonthlyComparison_Click
'Set SQL for report to show only selected department
Dim strSQL As String
Dim strDept As String
strDept = Forms!frmDept!cmbDept
strSQL = "SELECT qryPlantCrosstab.[Comment Subcategory],
Sum(qryPlantCrosstab.Jul) AS Jul, Sum(qryPlantCrosstab.Aug) AS Aug,
Sum(qryPlantCrosstab.Sep) AS Sep, Sum(qryPlantCrosstab.Oct) AS Oct,
Sum(qryPlantCrosstab.Nov) AS Nov, Sum(qryPlantCrosstab.Dec) AS [Dec],
Sum(qryPlantCrosstab.Jan) AS Jan, Sum(qryPlantCrosstab.Feb) AS Feb,
Sum(qryPlantCrosstab.Mar) AS Mar, Sum(qryPlantCrosstab.Apr) AS Apr,
Sum(qryPlantCrosstab.May) AS May, Sum(qryPlantCrosstab.Jun) AS Jun " & _
"FROM qryPlantCrosstab " & _
"WHERE (((qryPlantCrosstab.Classification) = " & Chr(34) &
strDept & Chr(34) & "))" & _
"GROUP BY qryPlantCrosstab.[Comment Subcategory] " & _
"ORDER BY Sum(qryPlantCrosstab.Jan) DESC;"
'Set the Source for the chart to the SQL created and open the report
Dim stDocName As String
Reports!rptMonthlyComparison.OLEUnbound0.RowSource = strSQL
stDocName = "rptMonthlyComparison"
DoCmd.OpenReport stDocName, acPreview
Exit_cmdOpenrptMonthlyComparison_Click:
Exit Sub
Err_cmdOpenrptMonthlyComparison_Click:
MsgBox Err.Description
Resume Exit_cmdOpenrptMonthlyComparison_Click
End Sub
chart on the report based on a combo box on the form. The problem I'm having
is that if I try to set it before I open the form then I get an error that
the form is not open. If I try to do it after opening, then I get an error
that you can't set the RowSource after printing has begun.
I'm thinking I need to pass my SQL string to the report somehow and then use
it maybe in the OnOpen event? Here's the code I'm trying to use...
Private Sub cmdOpenrptMonthlyComparison_Click()
On Error GoTo Err_cmdOpenrptMonthlyComparison_Click
'Set SQL for report to show only selected department
Dim strSQL As String
Dim strDept As String
strDept = Forms!frmDept!cmbDept
strSQL = "SELECT qryPlantCrosstab.[Comment Subcategory],
Sum(qryPlantCrosstab.Jul) AS Jul, Sum(qryPlantCrosstab.Aug) AS Aug,
Sum(qryPlantCrosstab.Sep) AS Sep, Sum(qryPlantCrosstab.Oct) AS Oct,
Sum(qryPlantCrosstab.Nov) AS Nov, Sum(qryPlantCrosstab.Dec) AS [Dec],
Sum(qryPlantCrosstab.Jan) AS Jan, Sum(qryPlantCrosstab.Feb) AS Feb,
Sum(qryPlantCrosstab.Mar) AS Mar, Sum(qryPlantCrosstab.Apr) AS Apr,
Sum(qryPlantCrosstab.May) AS May, Sum(qryPlantCrosstab.Jun) AS Jun " & _
"FROM qryPlantCrosstab " & _
"WHERE (((qryPlantCrosstab.Classification) = " & Chr(34) &
strDept & Chr(34) & "))" & _
"GROUP BY qryPlantCrosstab.[Comment Subcategory] " & _
"ORDER BY Sum(qryPlantCrosstab.Jan) DESC;"
'Set the Source for the chart to the SQL created and open the report
Dim stDocName As String
Reports!rptMonthlyComparison.OLEUnbound0.RowSource = strSQL
stDocName = "rptMonthlyComparison"
DoCmd.OpenReport stDocName, acPreview
Exit_cmdOpenrptMonthlyComparison_Click:
Exit Sub
Err_cmdOpenrptMonthlyComparison_Click:
MsgBox Err.Description
Resume Exit_cmdOpenrptMonthlyComparison_Click
End Sub