How can I duplicate the "even" function from Excel in Access?

  • Thread starter Thread starter Guest
  • Start date Start date
I think I have a solution for you. Here is a RoundUp function previously post
by T on microsoft.public.access.modulesdaovba.

Public Function RoundUp(dblnumber As Double) As Double
Dim dblfactor As Double
Dim dblTemp As Double
Dim intDecimals As Integer

intDecimals = 0

dblfactor = 10 ^ intDecimals
dblTemp = dblnumber * dblfactor + 0.9999
RoundUp = Int(dblTemp) / dblfactor
End Function

Once you have your roundup number test to see if it is odd or even with:
"YourNumber" Mod 2

If it returns 1 it is an even number. Just have to add 1 to get the next
even number.
 
Need to round up data entry with odd or fractional numbers to next "even"
integer.

Take a look at the VBA functions Fix(), CLng() and CInt() in the VBA
help. One of them should do the job for you.

Note that if your table field definitions define the field as an
Integer or Long Integer, it will round to the nearest whole number
automatically (and you CANNOT store fractions).

John W. Vinson[MVP]
 
With "even", do you mean mathematically even numbers, i.e. divisible by 2,
like 0 2 4 6 ... or do you mean whole number, i.e. no fractional part,
like 0 1 2 3 4 ...

If you meant the later (BTW, "integer" *already* implies no fractional
part), and you always want to round UP, i.e. nearly the same as:

CEILING({+ve number}, 1)

in Excel, use the expression:

-Int(-[YourPositiveNumber])

If you have to handle -ve numbers, test to make sure that it handles -ve
numbers the way you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top