Can you tell me what I need to do to add the function to my database.
Please tell me where to click step by step (I'm not a programmer).
First, find the Visual Basic editor by choosing Tools > Macros > Visual
Basic Editor;
Then create a new module to hold your function in, by choosing Insert >
Module
Then copy and paste the function definition given in the previous post[1]
from the Public Function line to the End Function line inclusive.
Choose Debug > Compile to make sure that the copy and past worked
properly.
Now you can use the function on your forms by typing something like this
into the ControlSource of the textbox (of course, you replace MyField
with whatever the name is of the field you want displayed).
= ToSixteenths([MyField])
[1] I've found Marsh's original complete function: it's here and I have
put in a wrapper so that it doesn't fall over with Nulls and other
illegal input:
' **** copy everything from here ****
Public Function CFractionRnd(X As Double) As String
' Marsh
' MVP [MS Access]
Dim Frac As Variant 'improved with Tim Ferguson ideas
Dim Y As Integer
Dim N As Integer
Frac = Array(Null, "1/8", "1/4", "3/8", "1/2", "5/8", "3/4", "7/8")
Y = Int(X + 1 / 16)
N = Int((X + 1 / 16 - Y) * 16) \ 2
If Y = 0 Then
CFractionRnd = IIf(N, Frac(N), "0")
Else
CFractionRnd = Y & (" " + Frac(N))
End If
End Function
Public Function CFRWrap(AValue As Variant) As Variant
If IsNull(AValue) Then
CFRWrap = Null
ElseIf Not IsNumeric(AValue) Then
CFRWrap = Null
Else
CFRWrap = CFractionRnd(CDbl(AValue))
End If
End Function
' **** copy everything down to here ****
and the function you put into the TextBox.Controlsource is
=CFRWrap([MyField])
Hope that helps
Tim F