MS Access Chart

I'd like to be able adjust the colour of a column chart (on a form) depending upon the series being graphed.  ie Lab is blue, Office is green etc.   There will only be 5 different series (areas) but the parameter query upon which the graph is based may have no data for the Lab in certain selected time periods, and the remaining areas will change colour.

I need assistance with what I assume will be a DLookup in order to make this work, automation error is generated at "With Me.Graph0.SeriesCollection(i)" line upon opening the form.  A run time error (1004 Unable to get the SeriesCollection property of the Chart class ) upon opening the form from design view is also generated by the same line - with 2 separate errors, was also wondering if the code is placed in the correct place.  

I've referenced Microsoft Graph 15.0 Object Library.

     Private Sub Graph0_Updated(Code As Integer)

   'tblColumnColours contains 2 fields, ColumnText which is name of each series (ie Lab, Office, Workshop) and ColumnColour
   
   Dim i As Integer
    With Me.Graph0.SeriesCollection(i)
        For i = 1 To .SeriesCollection.Count

            With .SeriesCollection(i)
                .Interior.Color = DLookup("ColumnColour", _
                                          "tblColumnColours", _
                                          "ColumnText = " & Chr(34) & .SeriesCollection(i) & Chr(34))
            End With
        Next i
    End With
    
    End Sub

Open in new window

padrepio2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try
    Private Sub Graph0_Updated(Code As Integer)

   'tblColumnColours contains 2 fields, ColumnText which is name of each series (ie Lab, Office, Workshop) and ColumnColour
   
   Dim i As Integer
    With Me.Graph0
        For i = 1 To .SeriesCollection.Count

            With .SeriesCollection(i)
                .Interior.Color = DLookup("ColumnColour", _
                                          "tblColumnColours", _
                                          "ColumnText = " & Chr(34) & .Name & Chr(34))
            End With
        Next i
    End With
    
    End Sub

Open in new window

EDIT corrected code

Regards
padrepio2Author Commented:
Hi

Have tried, runtime error (438) highlighting lines 9 to 12.  Object doesn't  support this property or method

Cheers
Rgonzo1971Commented:
Could you send a dummy?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

padrepio2Author Commented:
If you open the form, enter 1/1 (1st Jan) (parameter prompt appears twice since I've played with this graph)  and get rid of error by clicking 'End'.  Note the Lab colour.  Close and repeat with 1/10 (1st October), Workshop appears with what was the Lab colour.  I've used same code
Database2.accdb
Rgonzo1971Commented:
Sorry can't help further
padrepio2Author Commented:
Thanks for efforts/code tidy up
padrepio2Author Commented:
Anyone else able to assist?
JimFiveCommented:
My suggestion is to adjust your data source so that you always have all of the categories even if there is no data for the category.  To do this, start with a table that contains your categories and LEFT JOIN your data to that table.
--
Good Luck,
Jim
padrepio2Author Commented:
Thanks for the feedback Jim, have just tried this but the colours still changed.
JimFiveCommented:
Ok,
The problem is that the series does not have a name property, neither do the points.
So:
In the OnCurrent event of the form, put this code
Private Sub Form_Current()
   'tblColumnColours contains 2 fields, ColumnText which is name of each series (ie Lab, Workshop, Office) and ColumnColour containing colours, eg RGB(255, 0, 0)
   Dim i As Integer
   Dim chrt As Graph.Chart
   Dim srs As Graph.Series
   Dim nm As String
   
   Set chrt = Me.Graph0.Object
    For i = 1 To chrt.SeriesCollection.Count
        Set srs = chrt.SeriesCollection(i)
        nm = chrt.Application.DataSheet.Range(Chr(Asc("A") + i - 1) & "0")
        srs.Interior.Color = Eval(DLookup("ColumnColour", _
                                          "tblColumnColours", _
                                          "ColumnText = " & Chr(34) & nm & Chr(34)))
    Next
End Sub

Open in new window

I also added a code reference to Microsoft Graph 14, under Tools | References.

Remove the code in the Graph.Update event.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
padrepio2Author Commented:
Brilliant solution, many thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.