Using a public function

L

LeLe

I am creating work tickets which show diagrams for the different drapery
styles we produce. Some figures on the tickets appear or disappear depending
on whether or not they have a value > 0. Our employees are more accustom to
working with fractions when they measure, so if the value is visible I want
it to appear as a fraction. I would like to incorporate a great function I
got from this disuccsion group, into my code. I was able to use the function
on a "regular" form without the visible/not visible property, but can't seem
to make it work when I add back that feature. Any help is greatly
appreciated.

Here is the code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'Show the appropriate diagrams and measurements for either a Drapery panel
or pair. If the item neither, don't show any panels or pairs.

Select Case UOM

Case "Panel"
Me.DrapeRtFig.Visible = False
Me.DrapeLtFig.Visible = False
Me.WES_Lt.Visible = False
Me.WES_Rt.Visible = False
Me.LabLt.Visible = False
Me.LabRt.Visible = False
Me.OverRtPrFig.Visible = False
Me.RetLtPrFig.Visible = Me.ReturnL > 0
Me.Return.Visible = Me.ReturnL > 0
Me.Wds.Visible = Me.[Width/pnl] > 0
Me.Wds.Visible = Not Me.[Width/pnl] = 0
Me.DrapePnlFig.Visible = True
Me.OverRtPr.Visible = False

Case "Pair"
Me.DrapeRtFig.Visible = True
Me.DrapeLtFig.Visible = True
Me.WES_Lt.Visible = True
Me.WES_Rt.Visible = True
Me.LabLt.Visible = True
Me.LabRt.Visible = True
Me.OverRtPrFig.Visible = True
Me.Wds.Visible = False
Me.DrapePnlFig.Visible = False
Me.OverRtPr.Visible = True

Case "Each"
Me.DrapeRtFig.Visible = False
Me.DrapeLtFig.Visible = False
Me.WES_Lt.Visible = False
Me.WES_Rt.Visible = False
Me.LabLt.Visible = False
Me.LabRt.Visible = False
Me.OverRtPrFig.Visible = False
Me.Wds.Visible = False
Me.DrapePnlFig.Visible = False
End Select

'Show top header based on Headtop value
Me.headtop.Visible = Me.headtop > 0
Me.HeadTfig.Visible = Me.headtop > 0
Me.HeadTpic.Visible = Me.headtop > 0

'Show Bottom header based on HeadBot value
Me.headBot.Visible = Me.headBot > 0
Me.HeadBFig.Visible = Me.headBot > 0
Me.HeadBpic.Visible = Me.headBot > 0
Me.headBot.Visible = Not Me.headBot = 0
Me.HeadBFig.Visible = Not Me.headBot = 0
Me.HeadBpic.Visible = Not Me.headBot = 0

'hide hem if there is a Bottom Rod pkt
Me.HemFig.Visible = Me.rdpktBot = 0
Me.Hem.Visible = Me.rdpktBot = 0
Me.Hem.Visible = Not Me.rdpktBot > 0
Me.HemFig.Visible = Not Me.rdpktBot > 0
Me.HemFig.Visible = Me.rdpktTop = 0

Me.rdpktTop.Visible = Me.rdpktTop > 0
Me.RdPktBotPic.Visible = Me.rdpktTop > 0
Me.RdPktTopPic.Visible = Not Me.rdpktTop = 0
Me.Fulllness.Visible = Me.rdpktTop > 0

'Show bottom pkt if exists
Me.RdPktBotPic.Visible = Me.rdpktBot > 0
Me.RdPktBotPic.Visible = Not Me.rdpktBot = 0
Me.PktBfig.Visible = Me.rdpktBot > 0
Me.PktBfig.Visible = Not Me.rdpktBot = 0
Me.rdpktBot.Visible = Me.rdpktBot > 0
Me.rdpktBot.Visible = Not Me.rdpktBot = 0

If Me.headtop.Visible = True Then
FractionIt ([headtop])
End If
End Sub



Public Function FractionIt(dblNumIn As Double) As String
'===================================================
' Name: FractionIt
' Purpose: Converts a double into a string representing a rounded fraction
' Inputs: dblNumIn As Double
' Returns: String
' Author: Arvin Meyer
' Date: Revised - 6/22/2001
' Comment: Rounds down from 1/64 over
'========================================================
On Error GoTo Err_FractionIt

Dim strFrac As String
Dim strSign As String
Dim strWholeNum As String
Dim dblRem As Double

If dblNumIn < 0 Then
strSign = "-"
dblNumIn = dblNumIn * -1
Else
strSign = " "
End If

strWholeNum = Fix([dblNumIn])

dblRem = [dblNumIn] - [strWholeNum]

Select Case dblRem
Case 0
strFrac = ""
Case Is < 0.140625
strFrac = "1/8"
Case Is < 0.265625
strFrac = "1/4"
Case Is < 0.390625
strFrac = "3/8"
Case Is < 0.515625
strFrac = "1/2"
Case Is < 0.640625
strFrac = "5/8"
Case Is < 0.765625
strFrac = "3/4"
Case Is < 0.890625
strFrac = "7/8"
Case Is < 1
strFrac = "1"
End Select

If strFrac = "1" Then
FractionIt = strSign & (strWholeNum + 1)
Else
FractionIt = strSign & strWholeNum & "-" & strFrac
End If

Exit_FractionIt:
Exit Function

Err_FractionIt:
Select Case Err
Case 0

Case Else
MsgBox Err.Description
Resume Exit_FractionIt
End Select

End Function
 
T

Tom Wickerath

Hi LeLe,

Try adding a new text box to your form. Set the Control Source property like
this:

=FractionIt([FieldName])

where FieldName is the name of your field that contains the measure. For
example:

=FractionIt([DrapeRtFig])

Make sure that you give the text box(es) unique names that are *not* the
same as the field names. Something like this should work fine:
txtDrapeRtFigFraction


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

LeLe said:
I am creating work tickets which show diagrams for the different drapery
styles we produce. Some figures on the tickets appear or disappear depending
on whether or not they have a value > 0. Our employees are more accustom to
working with fractions when they measure, so if the value is visible I want
it to appear as a fraction. I would like to incorporate a great function I
got from this disuccsion group, into my code. I was able to use the function
on a "regular" form without the visible/not visible property, but can't seem
to make it work when I add back that feature. Any help is greatly
appreciated.

Here is the code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'Show the appropriate diagrams and measurements for either a Drapery panel
or pair. If the item neither, don't show any panels or pairs.

Select Case UOM

Case "Panel"
Me.DrapeRtFig.Visible = False
Me.DrapeLtFig.Visible = False
Me.WES_Lt.Visible = False
Me.WES_Rt.Visible = False
Me.LabLt.Visible = False
Me.LabRt.Visible = False
Me.OverRtPrFig.Visible = False
Me.RetLtPrFig.Visible = Me.ReturnL > 0
Me.Return.Visible = Me.ReturnL > 0
Me.Wds.Visible = Me.[Width/pnl] > 0
Me.Wds.Visible = Not Me.[Width/pnl] = 0
Me.DrapePnlFig.Visible = True
Me.OverRtPr.Visible = False

Case "Pair"
Me.DrapeRtFig.Visible = True
Me.DrapeLtFig.Visible = True
Me.WES_Lt.Visible = True
Me.WES_Rt.Visible = True
Me.LabLt.Visible = True
Me.LabRt.Visible = True
Me.OverRtPrFig.Visible = True
Me.Wds.Visible = False
Me.DrapePnlFig.Visible = False
Me.OverRtPr.Visible = True

Case "Each"
Me.DrapeRtFig.Visible = False
Me.DrapeLtFig.Visible = False
Me.WES_Lt.Visible = False
Me.WES_Rt.Visible = False
Me.LabLt.Visible = False
Me.LabRt.Visible = False
Me.OverRtPrFig.Visible = False
Me.Wds.Visible = False
Me.DrapePnlFig.Visible = False
End Select

'Show top header based on Headtop value
Me.headtop.Visible = Me.headtop > 0
Me.HeadTfig.Visible = Me.headtop > 0
Me.HeadTpic.Visible = Me.headtop > 0

'Show Bottom header based on HeadBot value
Me.headBot.Visible = Me.headBot > 0
Me.HeadBFig.Visible = Me.headBot > 0
Me.HeadBpic.Visible = Me.headBot > 0
Me.headBot.Visible = Not Me.headBot = 0
Me.HeadBFig.Visible = Not Me.headBot = 0
Me.HeadBpic.Visible = Not Me.headBot = 0

'hide hem if there is a Bottom Rod pkt
Me.HemFig.Visible = Me.rdpktBot = 0
Me.Hem.Visible = Me.rdpktBot = 0
Me.Hem.Visible = Not Me.rdpktBot > 0
Me.HemFig.Visible = Not Me.rdpktBot > 0
Me.HemFig.Visible = Me.rdpktTop = 0

Me.rdpktTop.Visible = Me.rdpktTop > 0
Me.RdPktBotPic.Visible = Me.rdpktTop > 0
Me.RdPktTopPic.Visible = Not Me.rdpktTop = 0
Me.Fulllness.Visible = Me.rdpktTop > 0

'Show bottom pkt if exists
Me.RdPktBotPic.Visible = Me.rdpktBot > 0
Me.RdPktBotPic.Visible = Not Me.rdpktBot = 0
Me.PktBfig.Visible = Me.rdpktBot > 0
Me.PktBfig.Visible = Not Me.rdpktBot = 0
Me.rdpktBot.Visible = Me.rdpktBot > 0
Me.rdpktBot.Visible = Not Me.rdpktBot = 0

If Me.headtop.Visible = True Then
FractionIt ([headtop])
End If
End Sub



Public Function FractionIt(dblNumIn As Double) As String
'===================================================
' Name: FractionIt
' Purpose: Converts a double into a string representing a rounded fraction
' Inputs: dblNumIn As Double
' Returns: String
' Author: Arvin Meyer
' Date: Revised - 6/22/2001
' Comment: Rounds down from 1/64 over
'========================================================
On Error GoTo Err_FractionIt

Dim strFrac As String
Dim strSign As String
Dim strWholeNum As String
Dim dblRem As Double

If dblNumIn < 0 Then
strSign = "-"
dblNumIn = dblNumIn * -1
Else
strSign = " "
End If

strWholeNum = Fix([dblNumIn])

dblRem = [dblNumIn] - [strWholeNum]

Select Case dblRem
Case 0
strFrac = ""
Case Is < 0.140625
strFrac = "1/8"
Case Is < 0.265625
strFrac = "1/4"
Case Is < 0.390625
strFrac = "3/8"
Case Is < 0.515625
strFrac = "1/2"
Case Is < 0.640625
strFrac = "5/8"
Case Is < 0.765625
strFrac = "3/4"
Case Is < 0.890625
strFrac = "7/8"
Case Is < 1
strFrac = "1"
End Select

If strFrac = "1" Then
FractionIt = strSign & (strWholeNum + 1)
Else
FractionIt = strSign & strWholeNum & "-" & strFrac
End If

Exit_FractionIt:
Exit Function

Err_FractionIt:
Select Case Err
Case 0

Case Else
MsgBox Err.Description
Resume Exit_FractionIt
End Select

End Function
 
Top