Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Number Rounding 1

Status
Not open for further replies.

breuht

MIS
Sep 28, 2004
1
0
0
US
When using the Roundup command in Microsfot Access I get an error, "Undefined function roundup' in expression". Does anyone know of an easy method to round up rather than the default down.
Example: 1.3 should equal 2.
Any help is appreciated.
Thanks
 
maybe you could do something like


Private function RoundUp(vrRoundedNumber as variant) as variant

if vrRoundedNumber / vrRoundedNumber <> 1 then
RoundUp = Round(1 + vrRoundedNumber , 0)
else
vrRoundedNumber = round(x,0)
end if

End function

Mark P.

Bleh
 
Hi Mark,

Can u pls help me with this?

The field name I have is AgeF and I wld like this field to ROUNDUP to the highest rather than down. How wld i code it in the above given example of yours :

Private function RoundUp(vrRoundedNumber as variant) as variant
if vrRoundedNumber / vrRoundedNumber <> 1 then
RoundUp = Round(1 + vrRoundedNumber , 0)
else
vrRoundedNumber = round(x,0)
end if
End function

Also where do I put the call for this field.. is it at Lost focus?

when the user inputs the raw scroes I wld like the calc I use to show the rounded age for the client. I am not great at coding so i am a bit stuck. Cld u possibly help me, it wld be greatly appreciated. and can I use it in a form Class module.

Am I am safe in saying that this is what it will look like or If I am wrong pls feel free to correct me

Private function RoundUp(AgeF as variant) as variant

if AgeF / Agef <> 1 then
RoundUp = Round(1 + AgeF , 0)
else
AgeF = round(x,0)
end if

End function


and can i place a call like

me.agef = roundup(me.agef)

thanks
 
Hi there.
You can make a new MODULE and paste Mark's code directly in there.

then wherever you want something rounded, just call it by:

Roundup(blah)

where blah can be anything you want rounded.

Depending on the situation, you could put, in a text box on a form or in a query:
=Roundup(blah)

or, yes, as you have above, you could put into the form's or another control's event:

me.Whatever = Roundup(blah)


 
Hi Mark,

Sorry for being a nuisance. I dont quite understnad , so can you lease help me.

This is my scenario.

I have a field called AgeNow which is in yrs and mths. Lets say the Yrs is 2 and the Mths is 8 I want the system to roundup and say the age at test was 3.
another ex: if the Yrs is 1 and the MThs is 3 I still want the numbers to get rounded up.. not down. So in this case it wld be 2.

the field that rec. the rounded UP number is called AgeNew.

The clients age cane be anything.. 1y.6 m; or 2y.5m; or 3y;2m

In this case how would your function work here.. can u please guide me.. can u use my field names as an example and tell me what goes where. thanks so much for your help.

U

 
What exactly does the data look like in the field AgeNow?

is it really

1y.6 m
2y.5m
3y;2m

with periods OR semi-colons and perhaps some spaces? If so, the function above won't work because it's based on the age being a number. How come you are saving the age in this format? Usually you'd just get the birth date and subtract from the current date, or some other date; what i mean is you calculate the age on-the-fly, since it changes daily. You just store the birth date since it never changes.

In any case, if you really do store the age and the reason for that turns out to be a valid one, the first thing i'd do is split that data up into two fields, AgeYears and AgeMonths so you can do calculations on it. Trying to do calcuations on a field that has no standard format, meaning someone can type anything they want in there, will be a nightmare.

Just my opinion....g

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I share Ginger's opinion.

Look up Calculating Date of Birth and figure out the DateDiff function, and the DateAdd function.

Mark P.
Providing Low Cost Powerful Point of Sale Solutions.
 
Once you get your data in the right form, a simple way to round up any value that's not an Integer is the expression

-1 * (Int(-1 * [FieldName]))

These are some of the values returned by the expression

1 = 1
1.1 = 2
2.9 = 3
3 = 3
etc.
It works with negative values as well.

Hope this helps.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top