2 replies
by dklippert
Access does not have a fraction format like Excel's.
I did find this code that will convert a text entered fraction to a decimal number.
=====================================
'This function will convert a fractional number entered as text
' into a numeric variant (you can force the type yourself)
'
'Fractional numbers must be entered as follows:
'
' "5 1/4" or "25-3/8", negative numbers are supported
'
' (c) 1999 by C. Knight
'
Public Function fncCalcFraction(ByVal frac As String) As Variant
Dim posn As Long 'used to find " " or "-"
On Error Resume Next 'Eval ) may cause error
frac = Trim$(frac) 'strip leading and trailing spaces
posn = InStr frac, " ") 'look for " "
If posn = 0 Then _
posn = InStr(2, frac, "-") 'not found, look for "-"
If posn > 0 Then 'got one of 'em
If Left$(frac, 1) = "-" Then 'is number negative?
Mid$(frac, posn, 1) = "-" 'yes, subtract fractional value
Else
Mid$(frac, posn, 1) = "+" 'no, add fractional value
End If
End If
'OK, our string now looks like "5+1/4" or "- -1/4", or it was non-numeric
'if so then eval will bomb and fncCalcFraction will return empty
fncCalcFraction = Eval(frac)
End Function
This discussion is closed to new replies.
Trending Software posts
Sort by Trending