robbie9
02-11-2001, 08:03 AM
I am using Access to price out Corian vanity tops. Its working great, except that I need to input thye sizes in Decimals..Is there a way I can use fractions?? I know in Excel there is a command that I can change to convert it to a fraction..Is there a way in Access??
R. Hicks
02-11-2001, 07:37 PM
I have a function that will convert a decimal number into a fraction, but the output is a string, not a number. The output is accurate to 1/128th of an inch.
'*******************Begin Code******************
Public Function DecimalToFraction(x)
Dim Temp As String
Dim Fixed As Double
If (VarType(x) < 2) Or (VarType(x) > 6) Then
DecimalToFraction = x
Else
x = Abs(x)
Fixed = Int(x)
If Fixed > 0 Then
Temp = str(Fixed)
End If
Select Case x - Fixed
Case Is < 0.007813
If Fixed > 0 Then
Temp = Temp
Else
Temp = str(x)
End If
Case 0.007813 To 0.023438
Temp = Temp + " 1/64"
Case 0.023438 To 0.039063
Temp = Temp + " 1/32"
Case 0.039063 To 0.054688
Temp = Temp + " 3/64"
Case 0.054688 To 0.070313
Temp = Temp + " 1/16"
Case 0.070313 To 0.085938
Temp = Temp + " 5/64"
Case 0.085938 To 0.101563
Temp = Temp + " 3/32"
Case 0.101563 To 0.117188
Temp = Temp + " 7/64"
Case 0.117188 To 0.132813
Temp = Temp + " 1/8"
Case 0.132813 To 0.148438
Temp = Temp + " 9/64"
Case 0.148438 To 0.164063
Temp = Temp + " 5/32"
Case 0.164063 To 0.179688
Temp = Temp + " 11/64"
Case 0.179688 To 0.195313
Temp = Temp + " 3/16"
Case 0.195313 To 0.210938
Temp = Temp + " 13/64"
Case 0.210938 To 0.226563
Temp = Temp + " 7/32"
Case 0.226563 To 0.242188
Temp = Temp + " 15/64"
Case 0.242188 To 0.257813
Temp = Temp + " 1/4"
Case 0.257813 To 0.273438
Temp = Temp + " 17/64"
Case 0.273438 To 0.289063
Temp = Temp + " 9/32"
Case 0.289063 To 0.304688
Temp = Temp + " 19/64"
Case 0.304688 To 0.320313
Temp = Temp + " 5/16"
Case 0.320313 To 0.335938
Temp = Temp + " 21/64"
Case 0.335938 To 0.351563
Temp = Temp + " 11/32"
Case 0.351563 To 0.367188
Temp = Temp + " 23/64"
Case 0.367188 To 0.382813
Temp = Temp + " 3/8"
Case 0.382813 To 0.398438
Temp = Temp + " 25/64"
Case 0.398438 To 0.414063
Temp = Temp + " 13/32"
Case 0.414063 To 0.429688
Temp = Temp + " 27/64"
Case 0.429688 To 0.445313
Temp = Temp + " 7/16"
Case 0.445313 To 0.460938
Temp = Temp + " 29/64"
Case 0.460938 To 0.476563
Temp = Temp + " 15/32"
Case 0.476563 To 0.492188
Temp = Temp + " 31/64"
Case 0.492188 To 0.507813
Temp = Temp + " 1/2"
Case 0.507813 To 0.523438
Temp = Temp + " 33/64"
Case 0.523438 To 0.539063
Temp = Temp + " 17/32"
Case 0.539063 To 0.554688
Temp = Temp + " 35/64"
Case 0.554688 To 0.570313
Temp = Temp + " 9/16"
Case 0.570313 To 0.585938
Temp = Temp + " 37/64"
Case 0.585938 To 0.601563
Temp = Temp + " 19/32"
Case 0.601563 To 0.617188
Temp = Temp + " 39/64"
Case 0.617188 To 0.632813
Temp = Temp + " 5/8"
Case 0.632813 To 0.648438
Temp = Temp + " 41/64"
Case 0.648438 To 0.664063
Temp = Temp + " 21/32"
Case 0.664063 To 0.679688
Temp = Temp + " 43/64"
Case 0.679688 To 0.695313
Temp = Temp + " 11/16"
Case 0.695313 To 0.710938
Temp = Temp + " 45/64"
Case 0.710938 To 0.726563
Temp = Temp + " 23/32"
Case 0.726563 To 0.742188
Temp = Temp + " 47/64"
Case 0.742188 To 0.757813
Temp = Temp + " 3/4"
Case 0.757813 To 0.773438
Temp = Temp + " 49/64"
Case 0.773438 To 0.789063
Temp = Temp + " 25/32"
Case 0.789063 To 0.804688
Temp = Temp + " 51/64"
Case 0.804688 To 0.820313
Temp = Temp + " 13/16"
Case 0.820313 To 0.835938
Temp = Temp + " 53/64"
Case 0.835938 To 0.851563
Temp = Temp + " 27/32"
Case 0.851563 To 0.867188
Temp = Temp + " 55/64"
Case 0.867188 To 0.882813
Temp = Temp + " 7/8"
Case 0.882813 To 0.898438
Temp = Temp + " 57/64"
Case 0.898438 To 0.914063
Temp = Temp + " 29/32"
Case 0.914063 To 0.929688
Temp = Temp + " 59/64"
Case 0.929688 To 0.945313
Temp = Temp + " 15/16"
Case 0.945313 To 0.960938
Temp = Temp + " 61/64"
Case 0.960938 To 0.976563
Temp = Temp + " 31/32"
Case 0.976563 To 0.992188
Temp = Temp + " 63/64"
Case Is > 0.992188
Temp = str(Int(x) + 1)
End Select
DecimalToFraction = Temp
End If
End Function
'*******************End Code******************
HTH
RDH
[This message has been edited by R. Hicks (edited 02-11-2001).]
robbie9
02-12-2001, 03:32 AM
Now if I am reading it right, DecimalToFraction if the name of the field..So I need to change it to my field name?? My field name is Length..
R. Hicks
02-12-2001, 04:55 AM
I guess I should have explained how to use the function.
Copy the function from the earlier post into a new module. Give this module a name like Fraction. You can then use the function as you would any other built-in function.
I'm not sure where you need tis info. So here are a couple of examples:
To see conversion on a form, insert a txtbox to receive the info on the form. Then for the control source of the txtbox put:
=DecimalToFraction([Length])
(where "Length" is the name of the txtbox that contains the Decimal equivalent)
If you need to convert the Decimal in a Query, use an expression in the query:
Exp1: http://www.access-programmers.co.uk/ubb/biggrin.gifecimalToFraction([Length])
(where "Length" is the field in the query that contains the Decimal equivalent)
Basically you use the function by substituting "x" in the function's argument for your decimal value reference.
DecimalToFraction(x)
HTH
RDH
[This message has been edited by R. Hicks (edited 02-12-2001).]
robbie9
02-12-2001, 05:39 AM
Now you really confused me.. So I don't have to change anything in the Formula?? After I input the Length, How does the formula get the Number??? Am I calling it up in the wrong spot?? or Do I need to change X to something??
R. Hicks
02-12-2001, 03:46 PM
It all depends on where the function is used. If your db is in Access 97, and not sensitive data, email a copy of it to me. Also let know where you want the fraction to show. I will see if I can give you a hand. If not, try to explain where you want the fraction to show (form, report...txtbox...ect) maybe I can build a sample db to incorporate the function to show you how to use it.
HTH
RDH
robbie9
02-13-2001, 03:17 AM
The DB is written in Access 2000.. So I can send it to you if you can use it.. What I am trying to do is, when I am Pricing the VAnity top, The only way I can Calculate the price is buy inputing the size with a Decimal (22.5 43.5 ect..) The problem is when the worksheet gets printed out, The guys in the shop have a tough time with the Decimals..We don't exactly have Rocket Scientists in the shop..So I would like it when I print out the sheet, it converts it to a fraction...
R. Hicks
02-13-2001, 04:55 AM
Try saving the db as Access 97 (Previous Version). Then email it to me, I should be able to read the db well enough to give you the answer you need.
RDH
robbie9
02-19-2001, 04:07 AM
I tried to send the Base to you, and it keeps coming back.. I got you email address off of here..Do I have the right one??
R. Hicks
02-19-2001, 01:38 PM
Try either of thr following Email addresses:
ricky@athree.com
rdhicks@mindspring.com
HTH
RDH
[This message has been edited by R. Hicks (edited 02-19-2001).]