How to Copy graphs from forms to reports ?? (1 Viewer)

carlton

New member
Local time
Today, 15:15
Joined
Oct 30, 2018
Messages
14
I have inherited a database which generates graphs on a form using an over complex series of queries
I need to be able to export the graphs to a .PDF document.
There are multiple graphs (31) which may be column or line graphs, each having different titles and axis labels. So far I have created a blank report with the appropriate page headers etc. which contains a chart object. The problem is I am unable to transfer the graph from the form to the report.
Also the commands I use to set the chart object titles and axis labels work for a form, but not for the chart object in the report.
For example
For the form
Set mainGraph = Forms!GraphTableDashboard!NavSubform!SubFormOSPlot!PlottingGraph.Object
mainGraph.ChartTitle.Caption = "A Chart Title "
Can be used to set the chart title, however taking the same approach on the report fails as the methods are not available.
Reports!ReportOSPlot_line!PlottingGraph.ChartTitle.Caption = "NEW TITLE" <<-- FAILS invalid method. :banghead:

I've been trawling the internet for some time now, and been unable to solve the problem.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:15
Joined
Oct 29, 2018
Messages
21,359
Hi. Is this related to your other thread?


Looking at the code you posted, it looks like you're using two different codes. The one on the form that works uses the Set command; whereas, the one on the report that doesn't work doesn't use the Set command.
 

June7

AWF VIP
Local time
Today, 07:15
Joined
Mar 9, 2014
Messages
5,425
I have graphs on form and report and use the same code to set graph properties. On a report the code must be called from Format event of section the graph is in.

However, ChartTitle is not property I had to programmatically change.

Here is one procedure. This is placed in a general module then the procedure is called by form and report.
Code:
Sub FormatVibGraph(strObject As String, strLabNum As String, booMetric As Boolean)
'format Vibratory graph form and report
Dim obj As Object
Dim gc As Object
Dim MinDD As Double
Dim MaxDD As Double
MinDD = Nz(DMin("Den", "GraphVibratory"), 0)
MaxDD = Nz(DMax("Den", "GraphVibratory"), 0)
If strObject Like "Lab*" Then
    Set obj = Reports(strObject)
Else
    Forms(strObject).Controls("ctrVibratory").Form
End If
Set gc = obj("gphDensity")
gc.Activate
If MinDD > 0 Then
    With gc
    .Axes(xlValue).MinimumScale = MinDD
    If booMetric = True Then
        MaxDD = Int(MaxDD / 100) * 100 + 100
        MinDD = MaxDD - 1000
        .Axes(xlValue).MaximumScale = MinDD
        .Axes(xlValue).MinimumScale = MinDD
        .Axes(xlValue).MajorUnit = 200
        .Axes(xlValue).MinorUnit = 40
    Else
        MaxDD = Int(MaxDD / 5) * 5 + 5
        MinDD = MaxDD - 50
        .Axes(xlValue).MaximumScale = MaxDD
        .Axes(xlValue).MinimumScale = MinDD
        .Axes(xlValue).MajorUnit = 10
        .Axes(xlValue).MinorUnit = 2
    End If
    .Axes(xlValue, xlPrimary).HasTitle = True
    If booMetric = True Then
        .Axes(xlValue, xlPrimary).AxisTitle.Text = "Max. Dry Density, Kg/cu.m"
    End If
    .Axes(xlCategory, xlPrimary).HasTitle = True
    If booMetric = True Then
        .Axes(xlCategory, xlPrimary).AxisTitle.Text = "Percent Passing 4.75 mm Sieve"
    End If
    End With
End If
End Sub
 

sonic8

AWF VIP
Local time
Today, 16:15
Joined
Oct 27, 2015
Messages
998
For the form
Set mainGraph = Forms!GraphTableDashboard!NavSubform!SubFormOSPlot!PlottingGraph.Object
mainGraph.ChartTitle.Caption = "A Chart Title "
Can be used to set the chart title, however taking the same approach on the report fails as the methods are not available.
Reports!ReportOSPlot_line!PlottingGraph.ChartTitle.Caption = "NEW TITLE" <<-- FAILS invalid method. :banghead:
You missed an important part of the original statement.

I reduced/simplified your code and higlight the difference:
Forms!SubFormOSPlot!PlottingGraph.Object.ChartTitle.Caption = "A Chart Title "
Reports!ReportOSPlot_line!PlottingGraph.ChartTitle.Caption = "NEW TITLE"
 

Users who are viewing this thread

Top Bottom