INFO: How to create one report with multiple chart options (1 Viewer)

isladogs

MVP / VIP
Local time
Today, 14:27
Joined
Jan 14, 2017
Messages
18,236
Hi

I regularly create forms which allow me to display different versions of the same chart.
For example, the attached form has 6 different types of chart 1-6 (day/week/month etc) each with 3 chart options a/b/c = 18 in all



Doing this on a form is easy enough - just set the chart row source using select case statements to display chart 4a, 3c etc

However reports are trickier as you can't set the chart row source after the report has opened or after 'printing' has started.
If you try to do so, you'll get error 438 - Object doesn't support this property or method.

However it isn't necessary to create 18 different reports to handle this!
One report will do nicely....e.g.



The solution is to set the report chart row source from the parent form BEFORE opening the report like this ....

Code:
Private Sub cmdPrint_Click()

Dim strChartValue As String, strReportName As String

On Error GoTo Err_Handler   

   'set report name 
    strReportName = "Your report name goes here"

  'set chart value for report open args - e.g. 3b ; 6a	
   strChartValue = Me.fraChartType & Me.fraChartOptions 
    
    'create dynamic record source for report based on strChartValue
   'strSQL statements are the same as those used already for form chart (in Select Case statements)
    CreateQuery "qryTemp", strSQL 
    
  'open report using Open Args
    DoCmd.OpenReport strReportName, acViewPreview,  ,  ,  , strChartValue

Exit_Handler:
    Exit Sub

Err_Handler:
    MsgBox "Error " & err.Number & " in cmdPrint_Click procedure: " & err.Description
    Resume Exit_Handler
End Sub


NOTE:
All other chart features CAN be set within the report e.g. data series colours / chart titles / axes etc
 

Attachments

  • MultiOptionChartForm.gif
    MultiOptionChartForm.gif
    40 KB · Views: 822
  • MultiOptionChartReportExample.gif
    MultiOptionChartReportExample.gif
    54.4 KB · Views: 382

Users who are viewing this thread

Top Bottom