Graph bar colours

L

LindaBee

I have a query about colour coding the bars on a graph. I have values in a
table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a chart is if the
number in a column is between 1 -4 then the bar shoould be Red and if the
numbers are 5 to 6 then the bar should be amber and if 8 to 10 then the bar
should be green. Can this be done if so how

Thanks

Linda
 
M

Maarkr

try this...it uses percent instead...this assumes you know some programming.
reply if you have questions.

Public Function PctMeter(varAmt As Variant, varTotal As Variant)
‘uses a label named baselbl and a txtCurrent and txtTotal field
‘call from AfterUpdate property of the txtTotal field
‘If Not IsNull(Me.txtTotal) And Not IsNull(Me.txtCurrent) Then
‘ Call PctMeter(Me.txtCurrent, Me.txtTotal)
‘End If
Dim sngPct As Single
sngPct = varAmt / varTotal
If sngPct <= 1 Then
Me!baselbl.Caption = Int(sngPct * 100) & "%"
Me!lblmeter.Width = CLng(Me!baselbl.Width * sngPct)
Else
Me!baselbl.Caption = "Greater than 100% - Check your amounts"
Me!lblmeter.Width = CLng(Me!baselbl.Width * 1)
End If
Select Case sngPct
Case Is < 0.15
Me!lblmeter.BackColor = 255
Case Is < 0.5
Me!lblmeter.BackColor = 65535
Case Else
Me!lblmeter.BackColor = 65280
End Select
End Function

....sorry if I lost the original author.
 
R

Rob Parker

Hi Linda,

Here's the code I use to do this. My chart is in a control named ChartName,
and I am colouring the points in the field named FieldName; you'll need to
change both of those to the names you have. The chart is in the Detail
section of the report, and the code is in the Format event of that section.
You'll need to change the values in the Select Case expression to suit
exactly what you want. This code sets the colour for the bar, the bar's
border, and the bar's label; if you don't want all of those changed, just
omit the approprite line(s).

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
With rst
.MoveFirst
For i = 1 To
Me.Controls("ChartName").SeriesCollection("FieldName").Points().Count
Set pnt =
Me.Controls("ChartName").SeriesCollection("FieldName").Points(i)
Select Case !FieldName
Case Is < 1
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("ChartName").SeriesCollection("FieldName").DataLabels(i).Font.Color
= vbRed
Case 1 To 5
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("ChartName").SeriesCollection("FieldName").DataLabels(i).Font.Color
= vbYellow
Case Is > 5
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("ChartName").SeriesCollection("FieldName").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing
End Sub

HTH,

Rob

PS. You haven't defined what will happen for points with a value of 7; and
if your data is not integer values, you'll also need to set the criteria in
the case statement to cover decimal values between, for example, 4 and 5. I
dealt with that by settting exact values for the centre range, and using <
and > to define the end ranges; I suggest you do the same.
 
L

LindaBee

Hi Rob
Thanks for the code I know about about programming code but not that good at
it.


When I create the chart the field is coming us as SumOfFieldname is this the
field name that I need to use. Cos I have tried replacing my FieldName with
my field name which is Social and nothing is hapening

Linda
 
R

Rob Parker

Hi Linda,

I'm not exactly sure what you've got - seems likely that your source for the
chart is a Totals query, in which case it may well have a field name
"SumOfSocial". Have you tried using that in the code I gave?

If that doesn't work, and you need more help, please post the SQL of the
chart's RowSource.

Rob
 
L

LindaBee

Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money, Table1.Safety,
Table1.Social, Table1.Choice, Table1.[Living skills], Table1.Independence,
Table1.mobility, Table1.culture, Table1.[mental health]
FROM Table1;


lINDA
 
R

Rob Parker

Hi Linda,

Is that query, which will return 11 fields, the RowSource of your chart
object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start, between the Set
rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

Open your report to run the code, then check the field names in the SQL
statement which will now be shown in the immediate window. Substitute the
name shown there for the field you want in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check this thread
again tomorrow morning.

Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money, Table1.Safety,
Table1.Social, Table1.Choice, Table1.[Living skills],
Table1.Independence, Table1.mobility, Table1.culture, Table1.[mental
health]
FROM Table1;


lINDA

Rob Parker said:
Hi Linda,

I'm not exactly sure what you've got - seems likely that your source
for the chart is a Totals query, in which case it may well have a
field name "SumOfSocial". Have you tried using that in the code I
gave?

If that doesn't work, and you need more help, please post the SQL of
the chart's RowSource.

Rob
 
L

LindaBee

Hi Rob
It is the RowSource of both report and chart at the moment I am just testing
one field to see if the colour changes depending on value teh field I am
testing is called Social

Linda

Rob Parker said:
Hi Linda,

Is that query, which will return 11 fields, the RowSource of your chart
object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start, between the Set
rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

Open your report to run the code, then check the field names in the SQL
statement which will now be shown in the immediate window. Substitute the
name shown there for the field you want in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check this thread
again tomorrow morning.

Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money, Table1.Safety,
Table1.Social, Table1.Choice, Table1.[Living skills],
Table1.Independence, Table1.mobility, Table1.culture, Table1.[mental
health]
FROM Table1;


lINDA

Rob Parker said:
Hi Linda,

I'm not exactly sure what you've got - seems likely that your source
for the chart is a Totals query, in which case it may well have a
field name "SumOfSocial". Have you tried using that in the code I
gave?

If that doesn't work, and you need more help, please post the SQL of
the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I have
values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a chart is
if the number in a column is between 1 -4 then the bar shoould be
Red and if the numbers are 5 to 6 then the bar should be amber and
if 8 to 10 then the bar should be green. Can this be done if so how

Thanks

Linda
 
L

LindaBee

Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
..MoveFirst
For i = 1 To Me.Controls(ChartName).SeriesCollection(Social).Points().Count
Set pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color =
vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color =
vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color =
vbGreen
Case Else
End Select
..MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

Rob Parker said:
Hi Linda,

Is that query, which will return 11 fields, the RowSource of your chart
object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start, between the Set
rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

Open your report to run the code, then check the field names in the SQL
statement which will now be shown in the immediate window. Substitute the
name shown there for the field you want in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check this thread
again tomorrow morning.

Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money, Table1.Safety,
Table1.Social, Table1.Choice, Table1.[Living skills],
Table1.Independence, Table1.mobility, Table1.culture, Table1.[mental
health]
FROM Table1;


lINDA

Rob Parker said:
Hi Linda,

I'm not exactly sure what you've got - seems likely that your source
for the chart is a Totals query, in which case it may well have a
field name "SumOfSocial". Have you tried using that in the code I
gave?

If that doesn't work, and you need more help, please post the SQL of
the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I have
values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a chart is
if the number in a column is between 1 -4 then the bar shoould be
Red and if the numbers are 5 to 6 then the bar should be amber and
if 8 to 10 then the bar should be green. Can this be done if so how

Thanks

Linda
 
R

Rob Parker

Hi Linda,

You don't say what's happening now, using your version of my code. Does it
work, or not? I would expect that it doesn't, since you've omitted some
very important delimiter characters (double-quotes) in your version, which
are necessary to pass the names of objects (controls, fields) when the code
is running.

You need to place double-quote characters around "ChartName" and "Social"
whenever those names appear in brackets. In addition, you need to replace
Chartname with the name of the chart object in your form/report. And, as I
said in my last post, check the SQL statement which the Debug.Print line
will generate in the immediate window of the VBA editor to ensure that
Social is the name of the field for which you want to change the colour of
the bars - it may be that the field is actually named SumOfSocial (or
something else) if you've used the chart wizard to generate your chart.

Also I note that your criteria (now used in the Case statements) are not
sufficiently accurate to cover the possible range of values. For instance,
if Social = 4 (if it's an integer datatype, or from 4 to 4.9999999999999 if
it's not an integer), none of the Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it much easier
to follow through if you use indenting as shown in my original code. Sure,
the spaces at the start of lines seem a bit of a waste, but (almost) every
programmer will consider them to be invaluable in following the program
flow. It really is worth it ;-)

Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count Set
pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

Rob Parker said:
Hi Linda,

Is that query, which will return 11 fields, the RowSource of your
chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start, between
the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new
line With rst

Open your report to run the code, then check the field names in the
SQL statement which will now be shown in the immediate window.
Substitute the name shown there for the field you want in the code I
posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.

Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money, Table1.Safety,
Table1.Social, Table1.Choice, Table1.[Living skills],
Table1.Independence, Table1.mobility, Table1.culture, Table1.[mental
health]
FROM Table1;


lINDA

:

Hi Linda,

I'm not exactly sure what you've got - seems likely that your
source for the chart is a Totals query, in which case it may well
have a field name "SumOfSocial". Have you tried using that in the
code I gave?

If that doesn't work, and you need more help, please post the SQL
of the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I have
values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a chart
is if the number in a column is between 1 -4 then the bar
shoould be Red and if the numbers are 5 to 6 then the bar should
be amber and if 8 to 10 then the bar should be green. Can this
be done if so how

Thanks

Linda
 
L

LindaBee

Rob
Nothing is happening when using the versionof your code, it does not seem to
be working.

About the Case statement how do you mean about acuracy the number wil be
whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

With rst
..MoveFirst
For i = 1 To Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color =
vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color =
vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color =
vbGreen
Case Else
End Select
..MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

Rob Parker said:
Hi Linda,

You don't say what's happening now, using your version of my code. Does it
work, or not? I would expect that it doesn't, since you've omitted some
very important delimiter characters (double-quotes) in your version, which
are necessary to pass the names of objects (controls, fields) when the code
is running.

You need to place double-quote characters around "ChartName" and "Social"
whenever those names appear in brackets. In addition, you need to replace
Chartname with the name of the chart object in your form/report. And, as I
said in my last post, check the SQL statement which the Debug.Print line
will generate in the immediate window of the VBA editor to ensure that
Social is the name of the field for which you want to change the colour of
the bars - it may be that the field is actually named SumOfSocial (or
something else) if you've used the chart wizard to generate your chart.

Also I note that your criteria (now used in the Case statements) are not
sufficiently accurate to cover the possible range of values. For instance,
if Social = 4 (if it's an integer datatype, or from 4 to 4.9999999999999 if
it's not an integer), none of the Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it much easier
to follow through if you use indenting as shown in my original code. Sure,
the spaces at the start of lines seem a bit of a waste, but (almost) every
programmer will consider them to be invaluable in following the program
flow. It really is worth it ;-)

Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count Set
pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

Rob Parker said:
Hi Linda,

Is that query, which will return 11 fields, the RowSource of your
chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start, between
the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new
line With rst

Open your report to run the code, then check the field names in the
SQL statement which will now be shown in the immediate window.
Substitute the name shown there for the field you want in the code I
posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money, Table1.Safety,
Table1.Social, Table1.Choice, Table1.[Living skills],
Table1.Independence, Table1.mobility, Table1.culture, Table1.[mental
health]
FROM Table1;


lINDA

:

Hi Linda,

I'm not exactly sure what you've got - seems likely that your
source for the chart is a Totals query, in which case it may well
have a field name "SumOfSocial". Have you tried using that in the
code I gave?

If that doesn't work, and you need more help, please post the SQL
of the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I have
values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a chart
is if the number in a column is between 1 -4 then the bar
shoould be Red and if the numbers are 5 to 6 then the bar should
be amber and if 8 to 10 then the bar should be green. Can this
be done if so how

Thanks

Linda
 
R

Rob Parker

Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that won't be
giving you the SQL for your chart's RowSource, to confirm the fieldname
which you should be using. And, once you've done that and got your code
working correctly, you can either remove or comment out the Debug.Print
line.

You've also got four lines of code duplicated. And (if you've cut/pasted
the code directly from the VBA editor) your Set pnt ... statement should not
be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the code
should change the colour of those points; points with any other value will
be unaffected, since they will not meet the criteria set in the Case
statements.

Try this (be careful of line wrap in your newsreader - and ensure that the
field name given by the Debug.Print statement really is "Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is <5
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have got from
your code. Is it correctly set up to run from the Format event of the
section of the report in which the chart control is located (ie. does the On
format field in the Property dialog for the section contain [Event
Procedure], and when you double-click the ... to the right of that, does
your code appear between Private Sub ... and End Sub lines)?

Rob
Nothing is happening when using the versionof your code, it does not
seem to be working.

About the Case statement how do you mean about acuracy the number wil
be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set pnt
= Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

Rob Parker said:
Hi Linda,

You don't say what's happening now, using your version of my code.
Does it work, or not? I would expect that it doesn't, since you've
omitted some very important delimiter characters (double-quotes) in
your version, which are necessary to pass the names of objects
(controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition, you
need to replace Chartname with the name of the chart object in your
form/report. And, as I said in my last post, check the SQL
statement which the Debug.Print line will generate in the immediate
window of the VBA editor to ensure that Social is the name of the
field for which you want to change the colour of the bars - it may
be that the field is actually named SumOfSocial (or something else)
if you've used the chart wizard to generate your chart.

Also I note that your criteria (now used in the Case statements) are
not sufficiently accurate to cover the possible range of values.
For instance, if Social = 4 (if it's an integer datatype, or from 4
to 4.9999999999999 if it's not an integer), none of the Case
statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it much
easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit of
a waste, but (almost) every programmer will consider them to be
invaluable in following the program flow. It really is worth it ;-)

Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count Set
pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of your
chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new
line With rst

Open your report to run the code, then check the field names in the
SQL statement which will now be shown in the immediate window.
Substitute the name shown there for the field you want in the code
I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money,
Table1.Safety, Table1.Social, Table1.Choice, Table1.[Living
skills], Table1.Independence, Table1.mobility, Table1.culture,
Table1.[mental health]
FROM Table1;


lINDA

:

Hi Linda,

I'm not exactly sure what you've got - seems likely that your
source for the chart is a Totals query, in which case it may well
have a field name "SumOfSocial". Have you tried using that in
the code I gave?

If that doesn't work, and you need more help, please post the SQL
of the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I have
values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a chart
is if the number in a column is between 1 -4 then the bar
shoould be Red and if the numbers are 5 to 6 then the bar
should be amber and if 8 to 10 then the bar should be green.
Can this be done if so how

Thanks

Linda
 
L

LindaBee

Hi Rob
I think I am a lost cause it is still not working now I will try for the
last time if it does not work then I will stop wasting your time.

Here is what I have a table with 10 colummns which will connatin values on
the bar and I have created a query to slect the 10 columns wnat I would like
the Query is called Query1 1 of the fields is called Social and I wnat to try
that one first now should the field name be Social or Query1 and the graph is
called RAS1

If I use a piece of code as an example have I got the this in the right order
For i = 1 To Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social

Controls should this be RAS1 (The graph name) and after SeriesCollection
should this be Social (one of the field names) or Query1 which is the
RowSource of the graph?

Thanks for your patience

Linda


Rob Parker said:
Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that won't be
giving you the SQL for your chart's RowSource, to confirm the fieldname
which you should be using. And, once you've done that and got your code
working correctly, you can either remove or comment out the Debug.Print
line.

You've also got four lines of code duplicated. And (if you've cut/pasted
the code directly from the VBA editor) your Set pnt ... statement should not
be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the code
should change the colour of those points; points with any other value will
be unaffected, since they will not meet the criteria set in the Case
statements.

Try this (be careful of line wrap in your newsreader - and ensure that the
field name given by the Debug.Print statement really is "Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is <5
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have got from
your code. Is it correctly set up to run from the Format event of the
section of the report in which the chart control is located (ie. does the On
format field in the Property dialog for the section contain [Event
Procedure], and when you double-click the ... to the right of that, does
your code appear between Private Sub ... and End Sub lines)?

Rob
Nothing is happening when using the versionof your code, it does not
seem to be working.

About the Case statement how do you mean about acuracy the number wil
be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set pnt
= Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

Rob Parker said:
Hi Linda,

You don't say what's happening now, using your version of my code.
Does it work, or not? I would expect that it doesn't, since you've
omitted some very important delimiter characters (double-quotes) in
your version, which are necessary to pass the names of objects
(controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition, you
need to replace Chartname with the name of the chart object in your
form/report. And, as I said in my last post, check the SQL
statement which the Debug.Print line will generate in the immediate
window of the VBA editor to ensure that Social is the name of the
field for which you want to change the colour of the bars - it may
be that the field is actually named SumOfSocial (or something else)
if you've used the chart wizard to generate your chart.

Also I note that your criteria (now used in the Case statements) are
not sufficiently accurate to cover the possible range of values.
For instance, if Social = 4 (if it's an integer datatype, or from 4
to 4.9999999999999 if it's not an integer), none of the Case
statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it much
easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit of
a waste, but (almost) every programmer will consider them to be
invaluable in following the program flow. It really is worth it ;-)


LindaBee wrote:
Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count Set
pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of your
chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new
line With rst

Open your report to run the code, then check the field names in the
SQL statement which will now be shown in the immediate window.
Substitute the name shown there for the field you want in the code
I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money,
Table1.Safety, Table1.Social, Table1.Choice, Table1.[Living
skills], Table1.Independence, Table1.mobility, Table1.culture,
Table1.[mental health]
FROM Table1;


lINDA

:

Hi Linda,

I'm not exactly sure what you've got - seems likely that your
source for the chart is a Totals query, in which case it may well
have a field name "SumOfSocial". Have you tried using that in
the code I gave?

If that doesn't work, and you need more help, please post the SQL
of the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I have
values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a chart
is if the number in a column is between 1 -4 then the bar
shoould be Red and if the numbers are 5 to 6 then the bar
should be amber and if 8 to 10 then the bar should be green.
Can this be done if so how

Thanks

Linda
 
R

Rob Parker

Hi Linda,

This seems to be getting us nowhere. I rarely do this, but I'm prepared to
do so now if it will help. If you send me your database (the .mdb file -
and if you're using Access 2007, you'll need to convert it to an earlier
format), I'll check it out and see what I can do. Email it to me at the
following address WITHOUT THE OBVIOUS SPAM TRAPS:
(e-mail address removed)

You can send a stripped down version with only the essential objects, and
only a few sample records in the underlying table(s) if you have privacy (or
other) problems with your complete data.

Rob

Hi Rob
I think I am a lost cause it is still not working now I will try for
the last time if it does not work then I will stop wasting your time.

Here is what I have a table with 10 colummns which will connatin
values on the bar and I have created a query to slect the 10 columns
wnat I would like the Query is called Query1 1 of the fields is
called Social and I wnat to try that one first now should the field
name be Social or Query1 and the graph is called RAS1

If I use a piece of code as an example have I got the this in the
right order For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i) Select
Case !Social

Controls should this be RAS1 (The graph name) and after
SeriesCollection should this be Social (one of the field names) or
Query1 which is the RowSource of the graph?

Thanks for your patience

Linda


Rob Parker said:
Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that
won't be giving you the SQL for your chart's RowSource, to confirm
the fieldname
which you should be using. And, once you've done that and got your
code working correctly, you can either remove or comment out the
Debug.Print
line.

You've also got four lines of code duplicated. And (if you've
cut/pasted
the code directly from the VBA editor) your Set pnt ... statement
should not be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the
code should change the colour of those points; points with any other
value will
be unaffected, since they will not meet the criteria set in the Case
statements.

Try this (be careful of line wrap in your newsreader - and ensure
that the field name given by the Debug.Print statement really is
"Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social Case Is <5 pnt.Interior.Color = vbRed
'set colour of bar pnt.Border.Color = vbRed 'set colour of
bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have got
from
your code. Is it correctly set up to run from the Format event of
the
section of the report in which the chart control is located (ie.
does the On format field in the Property dialog for the section
contain [Event
Procedure], and when you double-click the ... to the right of that,
does
your code appear between Private Sub ... and End Sub lines)?

Rob
Nothing is happening when using the versionof your code, it does not
seem to be working.

About the Case statement how do you mean about acuracy the number
wil be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set
pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

:

Hi Linda,

You don't say what's happening now, using your version of my code.
Does it work, or not? I would expect that it doesn't, since you've
omitted some very important delimiter characters (double-quotes) in
your version, which are necessary to pass the names of objects
(controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition, you
need to replace Chartname with the name of the chart object in your
form/report. And, as I said in my last post, check the SQL
statement which the Debug.Print line will generate in the immediate
window of the VBA editor to ensure that Social is the name of the
field for which you want to change the colour of the bars - it may
be that the field is actually named SumOfSocial (or something else)
if you've used the chart wizard to generate your chart.

Also I note that your criteria (now used in the Case statements)
are not sufficiently accurate to cover the possible range of
values. For instance, if Social = 4 (if it's an integer datatype,
or from 4 to 4.9999999999999 if it's not an integer), none of the
Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it much
easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit
of a waste, but (almost) every programmer will consider them to be
invaluable in following the program flow. It really is worth it
;-)


LindaBee wrote:
Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer) Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count Set
pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of your
chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the
new line With rst

Open your report to run the code, then check the field names in
the SQL statement which will now be shown in the immediate
window. Substitute the name shown there for the field you want
in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money,
Table1.Safety, Table1.Social, Table1.Choice, Table1.[Living
skills], Table1.Independence, Table1.mobility, Table1.culture,
Table1.[mental health]
FROM Table1;


lINDA

:

Hi Linda,

I'm not exactly sure what you've got - seems likely that your
source for the chart is a Totals query, in which case it may
well have a field name "SumOfSocial". Have you tried using
that in the code I gave?

If that doesn't work, and you need more help, please post the
SQL of the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I
have values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a
chart is if the number in a column is between 1 -4 then the
bar shoould be Red and if the numbers are 5 to 6 then the bar
should be amber and if 8 to 10 then the bar should be green.
Can this be done if so how

Thanks

Linda
 
L

LindaBee

Hi RoB
Seem to be having problems with the email address you have given me is there
another I can use

Linda

Rob Parker said:
Hi Linda,

This seems to be getting us nowhere. I rarely do this, but I'm prepared to
do so now if it will help. If you send me your database (the .mdb file -
and if you're using Access 2007, you'll need to convert it to an earlier
format), I'll check it out and see what I can do. Email it to me at the
following address WITHOUT THE OBVIOUS SPAM TRAPS:
(e-mail address removed)

You can send a stripped down version with only the essential objects, and
only a few sample records in the underlying table(s) if you have privacy (or
other) problems with your complete data.

Rob

Hi Rob
I think I am a lost cause it is still not working now I will try for
the last time if it does not work then I will stop wasting your time.

Here is what I have a table with 10 colummns which will connatin
values on the bar and I have created a query to slect the 10 columns
wnat I would like the Query is called Query1 1 of the fields is
called Social and I wnat to try that one first now should the field
name be Social or Query1 and the graph is called RAS1

If I use a piece of code as an example have I got the this in the
right order For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i) Select
Case !Social

Controls should this be RAS1 (The graph name) and after
SeriesCollection should this be Social (one of the field names) or
Query1 which is the RowSource of the graph?

Thanks for your patience

Linda


Rob Parker said:
Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that
won't be giving you the SQL for your chart's RowSource, to confirm
the fieldname
which you should be using. And, once you've done that and got your
code working correctly, you can either remove or comment out the
Debug.Print
line.

You've also got four lines of code duplicated. And (if you've
cut/pasted
the code directly from the VBA editor) your Set pnt ... statement
should not be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the
code should change the colour of those points; points with any other
value will
be unaffected, since they will not meet the criteria set in the Case
statements.

Try this (be careful of line wrap in your newsreader - and ensure
that the field name given by the Debug.Print statement really is
"Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social Case Is <5 pnt.Interior.Color = vbRed
'set colour of bar pnt.Border.Color = vbRed 'set colour of
bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have got
from
your code. Is it correctly set up to run from the Format event of
the
section of the report in which the chart control is located (ie.
does the On format field in the Property dialog for the section
contain [Event
Procedure], and when you double-click the ... to the right of that,
does
your code appear between Private Sub ... and End Sub lines)?


LindaBee wrote:
Rob
Nothing is happening when using the versionof your code, it does not
seem to be working.

About the Case statement how do you mean about acuracy the number
wil be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set
pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

:

Hi Linda,

You don't say what's happening now, using your version of my code.
Does it work, or not? I would expect that it doesn't, since you've
omitted some very important delimiter characters (double-quotes) in
your version, which are necessary to pass the names of objects
(controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition, you
need to replace Chartname with the name of the chart object in your
form/report. And, as I said in my last post, check the SQL
statement which the Debug.Print line will generate in the immediate
window of the VBA editor to ensure that Social is the name of the
field for which you want to change the colour of the bars - it may
be that the field is actually named SumOfSocial (or something else)
if you've used the chart wizard to generate your chart.

Also I note that your criteria (now used in the Case statements)
are not sufficiently accurate to cover the possible range of
values. For instance, if Social = 4 (if it's an integer datatype,
or from 4 to 4.9999999999999 if it's not an integer), none of the
Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it much
easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit
of a waste, but (almost) every programmer will consider them to be
invaluable in following the program flow. It really is worth it
;-)


LindaBee wrote:
Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer) Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count Set
pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of your
chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the
new line With rst

Open your report to run the code, then check the field names in
the SQL statement which will now be shown in the immediate
window. Substitute the name shown there for the field you want
in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money,
Table1.Safety, Table1.Social, Table1.Choice, Table1.[Living
 
R

Rob Parker

Have you removed the spam trap - ie. taken out all the upper-case letters?
If you do so, it's a valid email address - which I do NOT want to post in
clear form in a newsgroup.

Rob
Hi RoB
Seem to be having problems with the email address you have given me
is there another I can use

Linda

Rob Parker said:
Hi Linda,

This seems to be getting us nowhere. I rarely do this, but I'm
prepared to do so now if it will help. If you send me your database
(the .mdb file - and if you're using Access 2007, you'll need to
convert it to an earlier format), I'll check it out and see what I
can do. Email it to me at the following address WITHOUT THE OBVIOUS
SPAM TRAPS: (e-mail address removed)

You can send a stripped down version with only the essential
objects, and only a few sample records in the underlying table(s) if
you have privacy (or other) problems with your complete data.

Rob

Hi Rob
I think I am a lost cause it is still not working now I will try for
the last time if it does not work then I will stop wasting your
time.

Here is what I have a table with 10 colummns which will connatin
values on the bar and I have created a query to slect the 10 columns
wnat I would like the Query is called Query1 1 of the fields is
called Social and I wnat to try that one first now should the field
name be Social or Query1 and the graph is called RAS1

If I use a piece of code as an example have I got the this in the
right order For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i) Select
Case !Social

Controls should this be RAS1 (The graph name) and after
SeriesCollection should this be Social (one of the field names) or
Query1 which is the RowSource of the graph?

Thanks for your patience

Linda


:

Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that
won't be giving you the SQL for your chart's RowSource, to confirm
the fieldname
which you should be using. And, once you've done that and got your
code working correctly, you can either remove or comment out the
Debug.Print
line.

You've also got four lines of code duplicated. And (if you've
cut/pasted
the code directly from the VBA editor) your Set pnt ... statement
should not be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the
code should change the colour of those points; points with any
other value will
be unaffected, since they will not meet the criteria set in the
Case statements.

Try this (be careful of line wrap in your newsreader - and ensure
that the field name given by the Debug.Print statement really is
"Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social Case Is <5 pnt.Interior.Color = vbRed
'set colour of bar pnt.Border.Color = vbRed 'set colour of
bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have
got from
your code. Is it correctly set up to run from the Format event of
the
section of the report in which the chart control is located (ie.
does the On format field in the Property dialog for the section
contain [Event
Procedure], and when you double-click the ... to the right of that,
does
your code appear between Private Sub ... and End Sub lines)?


LindaBee wrote:
Rob
Nothing is happening when using the versionof your code, it does
not seem to be working.

About the Case statement how do you mean about acuracy the number
wil be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new
line With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set
pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

:

Hi Linda,

You don't say what's happening now, using your version of my
code. Does it work, or not? I would expect that it doesn't,
since you've omitted some very important delimiter characters
(double-quotes) in your version, which are necessary to pass the
names of objects (controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition,
you need to replace Chartname with the name of the chart object
in your form/report. And, as I said in my last post, check the
SQL statement which the Debug.Print line will generate in the
immediate window of the VBA editor to ensure that Social is the
name of the field for which you want to change the colour of the
bars - it may be that the field is actually named SumOfSocial
(or something else) if you've used the chart wizard to generate
your chart.

Also I note that your criteria (now used in the Case statements)
are not sufficiently accurate to cover the possible range of
values. For instance, if Social = 4 (if it's an integer datatype,
or from 4 to 4.9999999999999 if it's not an integer), none of the
Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it
much easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit
of a waste, but (almost) every programmer will consider them to
be invaluable in following the program flow. It really is worth
it ;-)


LindaBee wrote:
Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer) Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new
line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count
Set pnt =
Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of
your chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst =
db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the
new line With rst

Open your report to run the code, then check the field names in
the SQL statement which will now be shown in the immediate
window. Substitute the name shown there for the field you want
in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll
check this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money,
Table1.Safety, Table1.Social, Table1.Choice, Table1.[Living
 
R

Rob Parker

Final follow-up, for any-one else following this thread, or searching in
future:

I fixed Linda's problem. The problem with the code I posted originally was
that it was designed for a chart displaying multiple records (all records in
the chart's RowSource); Linda had a chart for each record in her report's
dataset, linked via a PersonRef field. The solution was to replace the
line:
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
with
Set rst = db.OpenRecordset("SELECT * FROM query1 WHERE PersonRef = '" &
Me.PersonRef & "';")
(note that PersonRef is a text datatype)

Additionally, the loop construct is not required since there is only one
record for each chart, and .Points(i) can be replaced with .Points(1). The
..SeriesCollection() index is the name of the field from query1, in this case
..SeriesCollection("Social")

Rob


Rob said:
Hi Linda,

This seems to be getting us nowhere. I rarely do this, but I'm
prepared to do so now if it will help. If you send me your database
(the .mdb file - and if you're using Access 2007, you'll need to
convert it to an earlier format), I'll check it out and see what I
can do. Email it to me at the following address WITHOUT THE OBVIOUS
SPAM TRAPS: (e-mail address removed)

You can send a stripped down version with only the essential objects,
and only a few sample records in the underlying table(s) if you have
privacy (or other) problems with your complete data.

Rob

Hi Rob
I think I am a lost cause it is still not working now I will try for
the last time if it does not work then I will stop wasting your time.

Here is what I have a table with 10 colummns which will connatin
values on the bar and I have created a query to slect the 10 columns
wnat I would like the Query is called Query1 1 of the fields is
called Social and I wnat to try that one first now should the field
name be Social or Query1 and the graph is called RAS1

If I use a piece of code as an example have I got the this in the
right order For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i) Select
Case !Social

Controls should this be RAS1 (The graph name) and after
SeriesCollection should this be Social (one of the field names) or
Query1 which is the RowSource of the graph?

Thanks for your patience

Linda


Rob Parker said:
Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that
won't be giving you the SQL for your chart's RowSource, to confirm
the fieldname
which you should be using. And, once you've done that and got your
code working correctly, you can either remove or comment out the
Debug.Print
line.

You've also got four lines of code duplicated. And (if you've
cut/pasted
the code directly from the VBA editor) your Set pnt ... statement
should not be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the
code should change the colour of those points; points with any other
value will
be unaffected, since they will not meet the criteria set in the Case
statements.

Try this (be careful of line wrap in your newsreader - and ensure
that the field name given by the Debug.Print statement really is
"Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social Case Is <5 pnt.Interior.Color = vbRed
'set colour of bar pnt.Border.Color = vbRed 'set colour of
bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have got
from
your code. Is it correctly set up to run from the Format event of
the
section of the report in which the chart control is located (ie.
does the On format field in the Property dialog for the section
contain [Event
Procedure], and when you double-click the ... to the right of that,
does
your code appear between Private Sub ... and End Sub lines)?


LindaBee wrote:
Rob
Nothing is happening when using the versionof your code, it does
not seem to be working.

About the Case statement how do you mean about acuracy the number
wil be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new
line With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set
pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

:

Hi Linda,

You don't say what's happening now, using your version of my code.
Does it work, or not? I would expect that it doesn't, since
you've omitted some very important delimiter characters
(double-quotes) in your version, which are necessary to pass the
names of objects (controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition,
you need to replace Chartname with the name of the chart object
in your form/report. And, as I said in my last post, check the
SQL statement which the Debug.Print line will generate in the
immediate window of the VBA editor to ensure that Social is the
name of the field for which you want to change the colour of the
bars - it may be that the field is actually named SumOfSocial (or
something else) if you've used the chart wizard to generate your
chart. Also I note that your criteria (now used in the Case
statements)
are not sufficiently accurate to cover the possible range of
values. For instance, if Social = 4 (if it's an integer datatype,
or from 4 to 4.9999999999999 if it's not an integer), none of the
Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it
much easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit
of a waste, but (almost) every programmer will consider them to be
invaluable in following the program flow. It really is worth it
;-)


LindaBee wrote:
Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer) Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new
line With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count
Set pnt =
Me.Controls(ChartName).SeriesCollection(Social).Points(i) Select
Case !Social Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of
your chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the
new line With rst

Open your report to run the code, then check the field names in
the SQL statement which will now be shown in the immediate
window. Substitute the name shown there for the field you want
in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money,
Table1.Safety, Table1.Social, Table1.Choice, Table1.[Living
skills], Table1.Independence, Table1.mobility, Table1.culture,
Table1.[mental health]
FROM Table1;


lINDA

:

Hi Linda,

I'm not exactly sure what you've got - seems likely that your
source for the chart is a Totals query, in which case it may
well have a field name "SumOfSocial". Have you tried using
that in the code I gave?

If that doesn't work, and you need more help, please post the
SQL of the chart's RowSource.

Rob


LindaBee wrote:
Sorry my field name is Social but coming up as SumOfSocial

Linda

:

I have a query about colour coding the bars on a graph. I
have values in a table I would like to convert into a chart.

The values range from 1 to 10. What I want displayed on a
chart is if the number in a column is between 1 -4 then the
bar shoould be Red and if the numbers are 5 to 6 then the
bar should be amber and if 8 to 10 then the bar should be
green. Can this be done if so how

Thanks

Linda
 
L

LindaBee

Rob
The graph works prefectly and I have you to thank for this. Your patience is
amazing.

This is for anyone who reads this post and needs help with graphs I think
Rob is amazing

Thanks a million

Linda

Rob Parker said:
Hi Linda,

This seems to be getting us nowhere. I rarely do this, but I'm prepared to
do so now if it will help. If you send me your database (the .mdb file -
and if you're using Access 2007, you'll need to convert it to an earlier
format), I'll check it out and see what I can do. Email it to me at the
following address WITHOUT THE OBVIOUS SPAM TRAPS:
(e-mail address removed)

You can send a stripped down version with only the essential objects, and
only a few sample records in the underlying table(s) if you have privacy (or
other) problems with your complete data.

Rob

Hi Rob
I think I am a lost cause it is still not working now I will try for
the last time if it does not work then I will stop wasting your time.

Here is what I have a table with 10 colummns which will connatin
values on the bar and I have created a query to slect the 10 columns
wnat I would like the Query is called Query1 1 of the fields is
called Social and I wnat to try that one first now should the field
name be Social or Query1 and the graph is called RAS1

If I use a piece of code as an example have I got the this in the
right order For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i) Select
Case !Social

Controls should this be RAS1 (The graph name) and after
SeriesCollection should this be Social (one of the field names) or
Query1 which is the RowSource of the graph?

Thanks for your patience

Linda


Rob Parker said:
Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that
won't be giving you the SQL for your chart's RowSource, to confirm
the fieldname
which you should be using. And, once you've done that and got your
code working correctly, you can either remove or comment out the
Debug.Print
line.

You've also got four lines of code duplicated. And (if you've
cut/pasted
the code directly from the VBA editor) your Set pnt ... statement
should not be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the
code should change the colour of those points; points with any other
value will
be unaffected, since they will not meet the criteria set in the Case
statements.

Try this (be careful of line wrap in your newsreader - and ensure
that the field name given by the Debug.Print statement really is
"Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social Case Is <5 pnt.Interior.Color = vbRed
'set colour of bar pnt.Border.Color = vbRed 'set colour of
bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have got
from
your code. Is it correctly set up to run from the Format event of
the
section of the report in which the chart control is located (ie.
does the On format field in the Property dialog for the section
contain [Event
Procedure], and when you double-click the ... to the right of that,
does
your code appear between Private Sub ... and End Sub lines)?


LindaBee wrote:
Rob
Nothing is happening when using the versionof your code, it does not
seem to be working.

About the Case statement how do you mean about acuracy the number
wil be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new line
With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set
pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

:

Hi Linda,

You don't say what's happening now, using your version of my code.
Does it work, or not? I would expect that it doesn't, since you've
omitted some very important delimiter characters (double-quotes) in
your version, which are necessary to pass the names of objects
(controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition, you
need to replace Chartname with the name of the chart object in your
form/report. And, as I said in my last post, check the SQL
statement which the Debug.Print line will generate in the immediate
window of the VBA editor to ensure that Social is the name of the
field for which you want to change the colour of the bars - it may
be that the field is actually named SumOfSocial (or something else)
if you've used the chart wizard to generate your chart.

Also I note that your criteria (now used in the Case statements)
are not sufficiently accurate to cover the possible range of
values. For instance, if Social = 4 (if it's an integer datatype,
or from 4 to 4.9999999999999 if it's not an integer), none of the
Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it much
easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit
of a waste, but (almost) every programmer will consider them to be
invaluable in following the program flow. It really is worth it
;-)


LindaBee wrote:
Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer) Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new line

With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count Set
pnt = Me.Controls(ChartName).SeriesCollection(Social).Points(i)
Select Case !Social
Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of your
chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the
new line With rst

Open your report to run the code, then check the field names in
the SQL statement which will now be shown in the immediate
window. Substitute the name shown there for the field you want
in the code I posted.

HTH,

Rob

PS. It's just on midnight here, and I'm off to bed. I'll check
this thread again tomorrow morning.


LindaBee wrote:
Rob
This is my SQL


SELECT Table1.PersonRef, Table1.Health, Table1.Money,
Table1.Safety, Table1.Social, Table1.Choice, Table1.[Living
 
H

hughess7

Hi, thanks for this great thread!! I am trying to achieve the same results
with my chart - i.e. colour the bar red if the value > 100 but I am having
trouble tweaking the code to match my scenario. Could you help please?

Code I have is:

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * from [Warranty Performance KPI Chart]
WHERE [Dealer] = '" & Me!Dealer & "'")

With rst
.MoveFirst

For i = 1 To Me.Controls("WP").SeriesCollection(Dealer).Points().Count
Set pnt = Me.Controls("WP").SeriesCollection(Dealer).Points(i)

Select Case !Dealer
Case Is > 100
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border

'Me.Controls("WP").SeriesCollection(Dealer).DataLabels(i).Font.Color = vbRed
Case Is < 100
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow

'Me.Controls("WP").SeriesCollection(Dealer).DataLabels(i).Font.Color =
vbYellow
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing

It loops through the code once, but on the 2nd run it errors with 'no
current record'. pnt doesn't seem to contain my field names either so unsure
if it is getting the recordset data properly, although it does run through
the code once?

Any ideas, thanks
Sue


Rob Parker said:
Final follow-up, for any-one else following this thread, or searching in
future:

I fixed Linda's problem. The problem with the code I posted originally was
that it was designed for a chart displaying multiple records (all records in
the chart's RowSource); Linda had a chart for each record in her report's
dataset, linked via a PersonRef field. The solution was to replace the
line:
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
with
Set rst = db.OpenRecordset("SELECT * FROM query1 WHERE PersonRef = '" &
Me.PersonRef & "';")
(note that PersonRef is a text datatype)

Additionally, the loop construct is not required since there is only one
record for each chart, and .Points(i) can be replaced with .Points(1). The
..SeriesCollection() index is the name of the field from query1, in this case
..SeriesCollection("Social")

Rob


Rob said:
Hi Linda,

This seems to be getting us nowhere. I rarely do this, but I'm
prepared to do so now if it will help. If you send me your database
(the .mdb file - and if you're using Access 2007, you'll need to
convert it to an earlier format), I'll check it out and see what I
can do. Email it to me at the following address WITHOUT THE OBVIOUS
SPAM TRAPS: (e-mail address removed)

You can send a stripped down version with only the essential objects,
and only a few sample records in the underlying table(s) if you have
privacy (or other) problems with your complete data.

Rob

Hi Rob
I think I am a lost cause it is still not working now I will try for
the last time if it does not work then I will stop wasting your time.

Here is what I have a table with 10 colummns which will connatin
values on the bar and I have created a query to slect the 10 columns
wnat I would like the Query is called Query1 1 of the fields is
called Social and I wnat to try that one first now should the field
name be Social or Query1 and the graph is called RAS1

If I use a piece of code as an example have I got the this in the
right order For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i) Select
Case !Social

Controls should this be RAS1 (The graph name) and after
SeriesCollection should this be Social (one of the field names) or
Query1 which is the RowSource of the graph?

Thanks for your patience

Linda


:

Hi again Linda,

You've still got "ChartName" in the Debug.Print statement, so that
won't be giving you the SQL for your chart's RowSource, to confirm
the fieldname
which you should be using. And, once you've done that and got your
code working correctly, you can either remove or comment out the
Debug.Print
line.

You've also got four lines of code duplicated. And (if you've
cut/pasted
the code directly from the VBA editor) your Set pnt ... statement
should not be continued from the previous line.

Your Case statements are now testing for values of 4 and 6, and the
code should change the colour of those points; points with any other
value will
be unaffected, since they will not meet the criteria set in the Case
statements.

Try this (be careful of line wrap in your newsreader - and ensure
that the field name given by the Debug.Print statement really is
"Social"; if it's
not, change it wherever it occurs):

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("RAS1").RowSource

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count
Set pnt =
Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social Case Is <5 pnt.Interior.Color = vbRed
'set colour of bar pnt.Border.Color = vbRed 'set colour of
bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed Case 5 to 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow Case Is> 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen

Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen Case Else
End Select
.MoveNext
Next i
End With

Set rst = Nothing
Set db = Nothing

Again, HTH,

Rob

PS. You haven't mentioned any error messages which you may have got
from
your code. Is it correctly set up to run from the Format event of
the
section of the report in which the chart control is located (ie.
does the On format field in the Property dialog for the section
contain [Event
Procedure], and when you double-click the ... to the right of that,
does
your code appear between Private Sub ... and End Sub lines)?


LindaBee wrote:
Rob
Nothing is happening when using the versionof your code, it does
not seem to be working.

About the Case statement how do you mean about acuracy the number
wil be whole numbers no decimals will be used.


Here is my revised code is it still wrong

Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Set rst = db.OpenRecordset(Me.Controls("RAS1").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the new
line With rst

With rst
.MoveFirst
For i = 1 To
Me.Controls("RAS1").SeriesCollection("Social").Points().Count Set
pnt = Me.Controls("RAS1").SeriesCollection("Social").Points(i)
Select Case !Social
Case Is = 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbRed
Case Is = 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbYellow
Case Is = 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls("RAS1").SeriesCollection("Social").DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
End With
Set rst = Nothing
Set rst = Nothing
Set db = Nothing

:

Hi Linda,

You don't say what's happening now, using your version of my code.
Does it work, or not? I would expect that it doesn't, since
you've omitted some very important delimiter characters
(double-quotes) in your version, which are necessary to pass the
names of objects (controls, fields) when the code is running.

You need to place double-quote characters around "ChartName" and
"Social" whenever those names appear in brackets. In addition,
you need to replace Chartname with the name of the chart object
in your form/report. And, as I said in my last post, check the
SQL statement which the Debug.Print line will generate in the
immediate window of the VBA editor to ensure that Social is the
name of the field for which you want to change the colour of the
bars - it may be that the field is actually named SumOfSocial (or
something else) if you've used the chart wizard to generate your
chart. Also I note that your criteria (now used in the Case
statements)
are not sufficiently accurate to cover the possible range of
values. For instance, if Social = 4 (if it's an integer datatype,
or from 4 to 4.9999999999999 if it's not an integer), none of the
Case statements will be executed.

Again, HTH,

Rob

PS. I notice that your code has no indenting. You'll find it
much easier to follow through if you use indenting as shown in my
original code. Sure, the spaces at the start of lines seem a bit
of a waste, but (almost) every programmer will consider them to be
invaluable in following the program flow. It really is worth it
;-)


LindaBee wrote:
Rob
This is how I have changed your code

Private Sub Detail_Format(Cancel As Integer, FormatCount As
Integer) Dim db As Database
Dim rst As DAO.Recordset
Dim pnt As Object
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.Controls(ChartName).RowSource)
Debug.Print Me.Controls(ChartName).RowSource 'this is the new
line With rst
.MoveFirst
For i = 1 To
Me.Controls(ChartName).SeriesCollection(Social).Points().Count
Set pnt =
Me.Controls(ChartName).SeriesCollection(Social).Points(i) Select
Case !Social Case Is < 4
pnt.Interior.Color = vbRed 'set colour of bar
pnt.Border.Color = vbRed 'set colour of bar's border
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbRed
Case 5 To 6
pnt.Interior.Color = vbYellow
pnt.Border.Color = vbYellow
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbYellow
Case Is > 6
pnt.Interior.Color = vbGreen
pnt.Border.Color = vbGreen
Me.Controls(ChartName).SeriesCollection(Social).DataLabels(i).Font.Color
= vbGreen
Case Else
End Select
.MoveNext
Next i
End With
Set rst = Nothing
Set db = Nothing


End Sub


Linda

:

Hi Linda,

Is that query, which will return 11 fields, the RowSource of
your chart object? Or is it the source of your report?

Perhaps this will help isolate the problem:

In the code I posted, add an additional line near the start,
between the Set rst ... and With rst ...lines, as follows:
Set rst = db.OpenRecordset(Me.Controls("ChartName").RowSource)
Debug.Print Me.Controls("ChartName").RowSource 'this is the
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top