Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 3333

# Microsoft Access - VBA , Round UP to next EVEN whole number

Hi folks,
Trying to round some measurements up to the next "EVEN - WHOLE NUMBER"

2.1 becomes 4
3.7 becomes 4
6.3 becomes 8
7.9 becomes 8

Seems to be a piece of cake in EXCEL with the EVEN function...  can anyone help me with the VBA code to use on a Access 2010 form?
0
TechGuise
• 7
• 6
• 5
2 Solutions

Commented:
Round Up

=-Int(-[YourFieldName])

Round Down:
=Int([YourFieldName])

mx
0

Commented:
Be sure to note the  Minus signs :-)
0

Author Commented:
Thanks for lightning fast response!  Just tried it.

Me.NewWidth.Value = -Int(-Me.POItemWidth.Value)

22.125 turns into 23
21 just stays at 21

Does what I have look right?
0

Commented:
yep.
Guaranteed to work in all case.
Most other schemes fail at some point.

mx
0

Author Commented:
Are you sure this will take it to the "NEXT EVEN NUMBER"  (like 2,4,6,8)
0

Author Commented:
Has something to do with the way the GLASS INDUSTRY charges for cutting glass
0

Commented:
try:
Dim tmpTXT2 As Double
tmpTXT2 = Text0
Text2 = -Int(-Text0)
If Text2 Mod 2 = 0 Then
If Text2 - tmpTXT2 < 1 Then
Exit Sub
Else
Text2 = Text2 + 2: Exit Sub
End If
End If
If Text2 = 0 Then Text2 = 2: Exit Sub
If Text2 = 1 Then Text2 = 2: Exit Sub
If Text2 \ 2 <> 0 Then Text2 = Text2 + 1
0

Commented:
Sorry ... I missed 'EVEN' ...
0

Commented:
This should work"

-Int(-[YourFieldName]) + (-Int(-[YourFieldName]) Mod 2)

mx
0

Commented:
looks much more elegant :-)
0

Author Commented:
You guys are awesome!   Both worked great.  Thanks!!
0

Author Commented:
Can I ask what MOD 2 does?
0

Commented:
Divides two numbers and returns only the remainder
and '\' returns the whole number :-) (sometimes called DIV
0

Author Commented:
Thank You!
0

Commented:
you're welcome!
0

Commented:
Thanks to Gustav Brock for the elegant Round Up/Down functions .... :-)

mx
0

Commented:
hear! hear!   (mine was very 'in-elegant') :-)
0

Commented:
COACHMAN99 ... you approach was fine. But thanks really to Gustav ... The Master of Date and Time, a more elegant approach exists :-)

mx
0

## Featured Post

• 7
• 6
• 5
Tackle projects and never again get stuck behind a technical roadblock.