What I have is a form, where I can select what to appear in the graphic
and
chart object to preview it. I know it is working fine, because I can
preview
the chart correctly.
== Begin of code in form
Public Function GenerateSQL() As String
Dim strData As String
Dim strSele As String
Dim strFrom As String
Dim strWher As String
strData = "SELECT MonthName, SumOfTime_LCBillable AS [Actual # of
Billable Days]," & _
[TextTargetLine] & " as [Target Line]" & _
" FROM [Billable Days - Monthly Attainment]" & _
" ORDER BY SortingMonth"
strData = "SELECT MS.MonthName, V1.Value " & _
"FROM [Graph - Month Sequence] AS MS LEFT JOIN [Graph -
Billable Days] AS V1 ON MS.SortingMonth = V1.SortingMonth " & _
"WHERE V1.Billable_FiscalYear = " & TextFiscalYear & _
" ORDER BY MS.SortingMonth"
strSele = "MS.MonthName, V1.Value as [Actual # of Billable days (" &
TextFiscalYear & ")]"
If ShowPreviousYear Then strSele = strSele & ", V2.Value as [Actual #
of
Billable days (" & TextFiscalYear - 1 & ")]"
If ShowTargetLine Then strSele = strSele & ", " & Nz(TextTargetLine, 0)
& " AS [Target Line]"
strFrom = "[Graph - Month Sequence] AS MS LEFT JOIN [Graph - Billable
Days] AS V1 ON MS.SortingMonth = V1.SortingMonth"
If ShowPreviousYear Then strFrom = "(" & strFrom & ") LEFT JOIN
[Graph -
Billable Days] AS V2 ON MS.SortingMonth = V2.SortingMonth"
strWher = "(V1.Billable_FiscalYear = " & TextFiscalYear & ")"
If ShowPreviousYear Then strWher = strWher & " AND
(V2.Billable_FiscalYear = " & TextFiscalYear - 1 & ")"
GenerateSQL = "SELECT " & strSele & " FROM " & strFrom & " WHERE " &
strWher & " ORDER BY MS.SortingMonth"
End Function
Private Sub btnPreview_Click()
On Error GoTo Err_btnPreview_Click
Dim stDocName As String
stDocName = "Graph - Billable Days - Monthly Attainment"
Me.Visible = False
DoCmd.OpenReport stDocName, acPreview
Exit_btnPreview_Click:
Exit Sub
Err_btnPreview_Click:
MsgBox Err.Description
Resume Exit_btnPreview_Click
End Sub
================ End of code in form
My report contains only a chart object an the code:
==== Begin code in report
Private Sub Report_Open(Cancel As Integer)
Dim strSQL As String
Const FormName = "Graph - Billable Days - Monthly Attainment"
If Not IsLoaded(FormName) Then
DoCmd.OpenForm FormName, , , , , acDialog
End If
strSQL = Forms(FormName).GenerateSQL
DoCmd.Close acForm, FormName
On Error GoTo ErrorHandler
Graph1.RowSource = strSQL
Graph1.Requery
Exit Sub
ErrorHandler:
If Err.Number <> 2455 Then MsgBox "Error: " & Err.Number & vbCrLf &
Err.Description, vbOKOnly + vbExclamation
Resume Next
End Sub
=============== End code in reprot
Even when I tried to apply the rowsource directly (Chart1.rowsource =
MySelectCommand) I've got the same error.
---
Mauricio Silva
Duane Hookom said:
Do you mind sharing your code?
Have you considered changing the SQL of a saved query (your chart's row
source) prior to opening the report?
--
Duane Hookom
MS Access MVP
message