None that I know of, but you can roll your own. This really demonstrates the power of using custom classes in vba.
To make this work you need to drop on any form
1)a label to be the background for your offset graph
2)a label to be the shaded region of your offset graph. I call it the face
3) a line to be the center point of your graph
4) a text box bound to your value.
This is the only code you need on your form to make this work. And that is the power of using custom classes.
Code:
Public osgPercent As OffSetGraph
Private Sub Form_Load()
Set osgPercent = New OffSetGraph
osgPercent.initOSG Me, Me.lblBack, Me.lblFace, Me.lnCenter, Me.txtBxValue, 0, 2
End Sub
The parameters are
the form (me)
the background label
the face label
the line
the text box that has the value
minimum value for the graph (default 0)
maxvalue for the graph (default 2/200%)
Only the background label needs to be properly located and sized, the code will properly format the line and the label for shading.
everything else is contained in the class module which can by used on any form. The code has to go in a class module not a standard module, and it has to be named OffsetGraph.
class OffSetGraph
Code:
Option Compare Database
Option Explicit
Private WithEvents mForm As Access.Form
Private mLblBack As Access.Label
Private mLblFace As Access.Label
Private mMinValue As Long
Private mMaxValue As Long
Private mWidth As Single
Private mHeight As Single
Private mCenterLocation As Single
Private mLine As Access.Line
Private mValueTextBox As Access.TextBox
Public Sub initOSG(theForm As Access.Form, LabelBack As Access.Label, LabelFace As Access.Label, CenterLine As Access.Line, ValueTextBox As Access.TextBox, Optional minValue As Long = 0, Optional maxValue As Long = 2)
Set mForm = theForm
Set mLblBack = LabelBack
Set mLblFace = LabelFace
Set mLine = CenterLine
Set mValueTextBox = ValueTextBox
mWidth = LabelBack.Width
mMinValue = minValue
mMaxValue = maxValue
mCenterLocation = mWidth / 2
formatLabelBack
formatLabelFace
formatCenterLine
mForm.OnCurrent = "[Event Procedure]"
End Sub
Public Sub formatLabelBack()
With mLblBack
'Sunken
.SpecialEffect = 2
.BorderWidth = 3
.BackColor = vbWhite
.Caption = ""
'normal
.BackStyle = 1
End With
End Sub
Private Sub formatLabelFace()
With mLblFace
'Raised
.SpecialEffect = 0
.BackColor = vbBlue
.Caption = ""
.BackStyle = 1
.Height = mLblBack.Height
.Top = mLblBack.Top
.Left = mLblBack.Left
End With
End Sub
Private Sub formatCenterLine()
With mLine
.Height = mLblBack.Height
.Top = mLblBack.Top
.Left = mLblBack.Left + mCenterLocation
.BorderWidth = 3
End With
End Sub
Private Sub mForm_Current()
locateBar
End Sub
Private Sub locateBar()
Dim currentValue As Single
Dim fractionSize As Single
currentValue = Nz(mValueTextBox.Value)
If currentValue >= 1 And currentValue <= mMaxValue Then
fractionSize = (currentValue - 1) / (mMaxValue - 1)
mLblFace.Width = fractionSize * (mWidth / 2)
mLblFace.Left = mLblBack.Left + mCenterLocation + mLine.BorderWidth / 2
ElseIf currentValue < 1 And currentValue >= mMinValue Then
fractionSize = (1 - currentValue) / (1 - mMinValue)
mLblFace.Width = fractionSize * (mWidth / 2)
mLblFace.Left = mLblBack.Left + mCenterLocation - mLine.BorderWidth / 2 - mLblFace.Width
ElseIf currentValue > mMaxValue Then
mLblFace.Width = (mWidth / 2)
mLblFace.Left = mLblBack.Left + mCenterLocation + mLine.BorderWidth / 2
MsgBox "Exceed Max Value"
ElseIf currentValue < mMinValue Then
mLblFace.Width = (mWidth / 2)
mLblFace.Left = mLblBack.Left + mCenterLocation - mLine.BorderWidth / 2 - mLblFace.Width
MsgBox "Min value exceeded"
End If
End Sub
Here is a working demo. I recycled this from some code that shaded a timeline.
Pretty slick, I have to admit.