General discussion

Locked

Fraction number format in Access

By Sabra_Krallman ·
How can I get a number to be formatted as a fraction in Access? Is there a add-in for it?

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Fraction number format in Access

by DKlippert In reply to Fraction number format in ...

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

Collapse -

Fraction number format in Access

by Sabra_Krallman In reply to Fraction number format in ...

Actually I need the opposite, decimal to fraction. Thanks.

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums