Line Graph line weight VBA code? (1 Viewer)

hfl

Registered User.
Local time
Today, 14:34
Joined
Sep 17, 2015
Messages
31
Hello,

I have a small problem with a line graph on a form, it's a "history graph" so it will only get more and more "lines" as time goes by.

Problem: Changing the line weight in the line graph with VBA.

I found this code online and it works for him but I get "Run-time error 438: Object doesn't support this property or method".

Code:
With Me.Graph_History.Charts(0).SeriesCollection(0)
    .Line.Weight = 6
End With

Access 2013
Microsoft Graph 16.0 Object Library

So was wondering if anyone can help me with this or do I just have to change them manually in the graph pattern option?

Thanks in advance :)
 

JHB

Have been here a while
Local time
Today, 14:34
Joined
Jun 17, 2012
Messages
7,732
Chart properties can be (mostly) a "pain" to work with, so could you post your database with sample data, + name of the form in which you've have the problem?
 

isladogs

MVP / VIP
Local time
Today, 13:34
Joined
Jan 14, 2017
Messages
18,211
Are you aware you can do this perfectly well without code

Click the chart & select edit.
Click a line and select Format Data Series & modify as appropriate
IIRC the settings (apart from colour) will stick to other lines ... unless modified individually) e.g.



Its probably easier still using the new 'modern' chart dialogs in Office 365
 

Attachments

  • Capture.PNG
    Capture.PNG
    36.4 KB · Views: 806
Last edited:

hfl

Registered User.
Local time
Today, 14:34
Joined
Sep 17, 2015
Messages
31
@ridders That's what I didn't get to work, it would only make that one line wider and not the others added later.

But I fixed it, I just added 10 lines, made them all wider one by one then I made a query to just keep the last 10 records for that ID sorted on date.

Thanks for the help :)
 

isladogs

MVP / VIP
Local time
Today, 13:34
Joined
Jan 14, 2017
Messages
18,211
You're welcome
Perhaps that's what I did but I don't remember doing so & I have up to 32 lines.
If I get time later today, I'll check for a code solution
 

isladogs

MVP / VIP
Local time
Today, 13:34
Joined
Jan 14, 2017
Messages
18,211
Just checked & in a chart report for the same app, I already had this code as part of the On Format event code for the section containing the chart.

It sets the line widths & scale for each axis
The bit in bold should do what you wanted.
It loops through each line in the chart collection...

Code:
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)

On Error GoTo Err_Handler

    'refresh chart for selected currencies
    [B]Dim i As Integer
    Dim objChart As Graph.Chart
    Dim objAxis As Object, objLine As Object
    
    Set objChart = Me.GraphDay.Object
    
    'set line width for each series
    For i = 1 To objChart.SeriesCollection.count
        Set objLine = objChart.SeriesCollection(i)
        
        With objLine.border
            .Weight = 4
        End With
    Next[/B]
    
    'y-axis scale
    Set objAxis = objChart.Axes(2) 'y-axis
    
    If objAxis.type = 2 Then 'Type 2 = Value
        objAxis.MaximumScale = Round(1.01 * DMax("Rate", "qryExchangeRates", "Base = '" & GetBaseCode & "' AND Use = True"), 2)
        objAxis.MinimumScale = Round(0.99 * DMin("Rate", "qryExchangeRates", "Base = '" & GetBaseCode & "' AND Use = True"), 2)
    End If
    
    'x-axis scale
    Set objAxis = objChart.Axes(1) 'x-axis
    
    If objAxis.type = 2 Then 'Type 2 = Value
        objAxis.MaximumScale = DMax("Date", "qryExchangeRates", "Base = '" & GetBaseCode & "' AND Use = True") + 1
        objAxis.MinimumScale = DMin("Date", "qryExchangeRates", "Base = '" & GetBaseCode & "' AND Use = True") - 1
    End If
    
    
Exit_Handler:
    Exit Sub
    
Err_Handler:
    MsgBox "Error " & Err.Number & " in PageHeaderSection_Format procedure : " & Err.Description
    Resume Exit_Handler

End Sub

I've also just created a new test chart object in a form and it works fine with the same code in the Form_Load event

HTH
 

Users who are viewing this thread

Top Bottom