Data bar

  • Thread starter Thread starter Alex H
  • Start date Start date
A

Alex H

Hi In the detail part of a report, i have a field [Value], and against each
I am wanting to place a bar to respresent the value ( rather like a
horizontal bar chart).

Iam using the following code:
Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If [Value] > MaxValue Then MaxValue = [Value]
BoxE1.Width = CLng(([Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True

I have tested for the value and that changes for each detail, but the bars
are all the same length for some reason.

Can anyone see what I've done wrong please

thanks

A
 
I adapted your code in my database and it worked perfectly.
Make sure you put your code in the OnPrint event.

Mauricio Silva 2005
 
I have it in the OnFormat event of the detailsection. if I put it in the
OnPrint, I get a method not supported errormessage
A

Mauricio Silva said:
I adapted your code in my database and it worked perfectly.
Make sure you put your code in the OnPrint event.

Mauricio Silva 2005

Alex H said:
Hi In the detail part of a report, i have a field [Value], and against
each
I am wanting to place a bar to respresent the value ( rather like a
horizontal bar chart).

Iam using the following code:
Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If [Value] > MaxValue Then MaxValue = [Value]
BoxE1.Width = CLng(([Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True

I have tested for the value and that changes for each detail, but the
bars
are all the same length for some reason.

Can anyone see what I've done wrong please

thanks

A
 
You can't set the width in the On Print. Your code must be in the On Format
event of the section containing the control. I'm not sure why you need to
use MaxValue if it is always going to be 0. Also, leaving MaxValue = 0 would
cause a divide by 0 error.

It looks like MaxValue and Value will always be equal so the control will
always have a length of 567*7.

Where does Value come from? If it is a text box on your report then I would
use code like:

Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If Me.[Value] > MaxValue Then
MaxValue = Me.[Value]
End If

BoxE1.Width = CLng((Me.[Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True


--
Duane Hookom
MS Access MVP
--

Alex H said:
I have it in the OnFormat event of the detailsection. if I put it in the
OnPrint, I get a method not supported errormessage
A

Mauricio Silva said:
I adapted your code in my database and it worked perfectly.
Make sure you put your code in the OnPrint event.

Mauricio Silva 2005

Alex H said:
Hi In the detail part of a report, i have a field [Value], and against
each
I am wanting to place a bar to respresent the value ( rather like a
horizontal bar chart).

Iam using the following code:
Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If [Value] > MaxValue Then MaxValue = [Value]
BoxE1.Width = CLng(([Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True

I have tested for the value and that changes for each detail, but the
bars
are all the same length for some reason.

Can anyone see what I've done wrong please

thanks

A
 
Duane- thanks foryour post and help.
I had copied my code from another report where it works perfectly, albeit
that the value of [Value] was being set within the code.

However in this report, yes the figure for [Value] is coming from a text box
and is displayed Ok. However I have tried your code and still get the same
problem - however am i still not setting [Value] to the same as MaxValue

Alex


Duane Hookom said:
You can't set the width in the On Print. Your code must be in the On
Format event of the section containing the control. I'm not sure why you
need to use MaxValue if it is always going to be 0. Also, leaving MaxValue
= 0 would cause a divide by 0 error.

It looks like MaxValue and Value will always be equal so the control will
always have a length of 567*7.

Where does Value come from? If it is a text box on your report then I
would use code like:

Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If Me.[Value] > MaxValue Then
MaxValue = Me.[Value]
End If

BoxE1.Width = CLng((Me.[Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True


--
Duane Hookom
MS Access MVP
--

Alex H said:
I have it in the OnFormat event of the detailsection. if I put it in the
OnPrint, I get a method not supported errormessage
A

Mauricio Silva said:
I adapted your code in my database and it worked perfectly.
Make sure you put your code in the OnPrint event.

Mauricio Silva 2005

:

Hi In the detail part of a report, i have a field [Value], and against
each
I am wanting to place a bar to respresent the value ( rather like a
horizontal bar chart).

Iam using the following code:
Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If [Value] > MaxValue Then MaxValue = [Value]
BoxE1.Width = CLng(([Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True

I have tested for the value and that changes for each detail, but the
bars
are all the same length for some reason.

Can anyone see what I've done wrong please

thanks

A
 
My code would not fix anything other than make it clearer. Where should
maxvalue come from other than being 0?
I expect Me.Value will always be greater than MaxValue since MaxValue equals
0. Therefore, you are always multiplying your constant value by 1.

You should be getting MaxValue from someplace rather than assigning it a
value of 0.

--
Duane Hookom
MS Access MVP
--

Alex H said:
Duane- thanks foryour post and help.
I had copied my code from another report where it works perfectly, albeit
that the value of [Value] was being set within the code.

However in this report, yes the figure for [Value] is coming from a text
box and is displayed Ok. However I have tried your code and still get the
same problem - however am i still not setting [Value] to the same as
MaxValue

Alex


Duane Hookom said:
You can't set the width in the On Print. Your code must be in the On
Format event of the section containing the control. I'm not sure why you
need to use MaxValue if it is always going to be 0. Also, leaving
MaxValue = 0 would cause a divide by 0 error.

It looks like MaxValue and Value will always be equal so the control will
always have a length of 567*7.

Where does Value come from? If it is a text box on your report then I
would use code like:

Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If Me.[Value] > MaxValue Then
MaxValue = Me.[Value]
End If

BoxE1.Width = CLng((Me.[Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True


--
Duane Hookom
MS Access MVP
--

Alex H said:
I have it in the OnFormat event of the detailsection. if I put it in the
OnPrint, I get a method not supported errormessage
A

message
I adapted your code in my database and it worked perfectly.
Make sure you put your code in the OnPrint event.

Mauricio Silva 2005

:

Hi In the detail part of a report, i have a field [Value], and against
each
I am wanting to place a bar to respresent the value ( rather like a
horizontal bar chart).

Iam using the following code:
Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If [Value] > MaxValue Then MaxValue = [Value]
BoxE1.Width = CLng(([Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True

I have tested for the value and that changes for each detail, but the
bars
are all the same length for some reason.

Can anyone see what I've done wrong please

thanks

A
 
First, I apologise for the OnPrint (I don't know where my mind was).

As I said, I adapted the code to use it because this MaxValue thing. I
believe it must be a TextBox with a query to get the Max(Value) from the
report, before it is printed.

Mauricio Silva

Duane Hookom said:
My code would not fix anything other than make it clearer. Where should
maxvalue come from other than being 0?
I expect Me.Value will always be greater than MaxValue since MaxValue equals
0. Therefore, you are always multiplying your constant value by 1.

You should be getting MaxValue from someplace rather than assigning it a
value of 0.

--
Duane Hookom
MS Access MVP
--

Alex H said:
Duane- thanks foryour post and help.
I had copied my code from another report where it works perfectly, albeit
that the value of [Value] was being set within the code.

However in this report, yes the figure for [Value] is coming from a text
box and is displayed Ok. However I have tried your code and still get the
same problem - however am i still not setting [Value] to the same as
MaxValue

Alex


Duane Hookom said:
You can't set the width in the On Print. Your code must be in the On
Format event of the section containing the control. I'm not sure why you
need to use MaxValue if it is always going to be 0. Also, leaving
MaxValue = 0 would cause a divide by 0 error.

It looks like MaxValue and Value will always be equal so the control will
always have a length of 567*7.

Where does Value come from? If it is a text box on your report then I
would use code like:

Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If Me.[Value] > MaxValue Then
MaxValue = Me.[Value]
End If

BoxE1.Width = CLng((Me.[Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True


--
Duane Hookom
MS Access MVP
--

I have it in the OnFormat event of the detailsection. if I put it in the
OnPrint, I get a method not supported errormessage
A

message
I adapted your code in my database and it worked perfectly.
Make sure you put your code in the OnPrint event.

Mauricio Silva 2005

:

Hi In the detail part of a report, i have a field [Value], and against
each
I am wanting to place a bar to respresent the value ( rather like a
horizontal bar chart).

Iam using the following code:
Const MaxBarWidth = 567 * 7
Dim MaxValue As Double

MaxValue = 0
If [Value] > MaxValue Then MaxValue = [Value]
BoxE1.Width = CLng(([Value] / MaxValue) * MaxBarWidth)
BoxE1.Visible = True

I have tested for the value and that changes for each detail, but the
bars
are all the same length for some reason.

Can anyone see what I've done wrong please

thanks

A
 
Back
Top