timamartin
asked on
Graphic representation of a percentage on a report
Somewhere I saw somebody mention a good way to depict a percentage as a little bar on a report. It entailed drawing a rectangle on top of a rectangle and controlling the width of one (filled) to represent the percentage and the other (unfilled) showing an outline representing 100%
Snap1156.jpg
Snap1156.jpg
ASKER
Detail - On Format - Code Builder
I can't get this to work -- even if I set Me.box.Width = .5
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.boxFront.Width = Me.boxBack.Width / Me.Pct_Comp
End Sub
I can't get this to work -- even if I set Me.box.Width = .5
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.boxFront.Width = Me.boxBack.Width / Me.Pct_Comp
End Sub
Please note that the measurements for this (using code) is in "Twips", not inches.
1 inch =1440 twips
So, for example, your Box width is probably going to be 720 not .5 inches
JeffCoachman
1 inch =1440 twips
So, for example, your Box width is probably going to be 720 not .5 inches
JeffCoachman
ASKER
What happens if the process is not started and the percentage = 0% will I get a dived by 0 error?
Yes; you should check for this first:
If Me.Pct_Comp <> 0 Then
If Me.Pct_Comp <> 0 Then
ASKER
Am I supposed to put something different in the properties sheet? Rather than the starting width of the variable rectangle?
I'll post a sample of how I do this tonight, as an example
I think to get the effect you are after you may have to "Invert" your logic
In other words, in order for a number close to the max, to leave just a sliver of whitespace, on the Right of the bar, you may have to change the way the box "Grows".
Jeff
I think to get the effect you are after you may have to "Invert" your logic
In other words, in order for a number close to the max, to leave just a sliver of whitespace, on the Right of the bar, you may have to change the way the box "Grows".
Jeff
ASKER
Ok..here is what I have and for some reason it will not work for me. assuming that the box starts out as 1500 twips, multiplying 15 x % should give me the correct number. unfortunately, the bar size never changes. they are all the same size.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Pct_Comp > 0 Then
Me.boxFront.Width = 15 * Me.Pct_Comp
End If
End Sub
snap01156.jpg
Since yopu are not showning any of the values you are using, I can't say with any confidence, what is happening.
I us a formula similar to LSM's:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'BoxRed is "In front of" BoxWhite.
Me.BoxRed.Width = Me.BoxWhite.Width * Me.Percentage
End Sub
Here is the sample I promissed
JeffCoachman
Access-EEQ24463539SimplePercentB.mdb
untitled.JPG
I us a formula similar to LSM's:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'BoxRed is "In front of" BoxWhite.
Me.BoxRed.Width = Me.BoxWhite.Width * Me.Percentage
End Sub
Here is the sample I promissed
JeffCoachman
Access-EEQ24463539SimplePercentB.mdb
untitled.JPG
ASKER
I fell like an idiot because I still can't get this to work. I will go into more detail and hopefully I can.
First make sure that you try what LSM has suggested first.
My posts were just another way of doing the same thing.
Keep trying, It is probaly something simple.
;-)
Keep us posted.
JeffCoachman
My posts were just another way of doing the same thing.
Keep trying, It is probaly something simple.
;-)
Keep us posted.
JeffCoachman
ASKER
Ok...I'm back at it...
The event that I am using is Detail -- On format --
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.boxFront.Width = 20
End Sub
at this point all I want to do is get the bar size to reflect a number in the report -- in this case 20. After I get that to happen I will move on to part 2.
The event that I am using is Detail -- On format --
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.boxFront.Width = 20
End Sub
at this point all I want to do is get the bar size to reflect a number in the report -- in this case 20. After I get that to happen I will move on to part 2.
ASKER
Ok...I give up. I am uploading a simplified version of the DB
ASKER
Whoops here is the attachment...it wouldn't let me upload the file so I changed the extension from .accdb to .txt make sure you change it back to see it. Also...if it asks for a PW it's 'status'
zz.txt
zz.txt
ASKER
Is the problem because I am trying to do this in a report? There must be a way to do it.
And the password is.....?
ASKER
status
ASKER
The password is 'status'
OK
Look at this sub:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.boxFront.Width = Me.boxBack * Me.Pct_Comp
End Sub
Notice anything missing when you compare your own code posted in http:#a24547956?
Also what is Pct_Comp, and where is it defined?
Everything you need is in the sample I posted.
You must study it "Carefully", then replicate it in your dadatbase.
JeffCoachman
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.boxFront.Width = Me.boxBack * Me.Pct_Comp
End Sub
Notice anything missing when you compare your own code posted in http:#a24547956?
Also what is Pct_Comp, and where is it defined?
Everything you need is in the sample I posted.
You must study it "Carefully", then replicate it in your dadatbase.
JeffCoachman
ASKER
I think there must be a global settings or something that is stopping this from working.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Box3.Width = 1.5
End Sub
Even this won't change the size of the bar -- nothing seems to affect it.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Box3.Width = 1.5
End Sub
Even this won't change the size of the bar -- nothing seems to affect it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mine eyes have been opened! Holy cow missed that little item about only working in print preview. So now for the big question....why does it only work in print preview?
Come on you knew it was coming.
Come on you knew it was coming.
ASKER
Thanks for the help!
;-)
In a nutshell Print preview was always designed to present the report "Exactly" as it will look when printed.
That's great.
The issue is that sometimes code, large graphics, complex designs, ...ect can slow down previewing a report.
Hence "Report View" was born.
No code, no page breaks, just a quick "view" of the report.
;-)
By the way, congratulation for getting this working on your own.
(Well, almost anyway ;-) )
It shows that you are persistient, and smart.
;-)
Jeff
In a nutshell Print preview was always designed to present the report "Exactly" as it will look when printed.
That's great.
The issue is that sometimes code, large graphics, complex designs, ...ect can slow down previewing a report.
Hence "Report View" was born.
No code, no page breaks, just a quick "view" of the report.
;-)
By the way, congratulation for getting this working on your own.
(Well, almost anyway ;-) )
It shows that you are persistient, and smart.
;-)
Jeff
Me.boxFront.Width = (me.boxBack.Width / Me.SomePercentageField)
So, if your SomePercentageField is, say, 80%, the width of boxFront would be 80% of the width of the "rear" rectangle.
You'd probably do this in the report's Format or Print event of the appropriate section (generally the Detail section).