Solved

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

Posted on 2014-03-20
18
3,057 Views
Last Modified: 2014-03-21
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
Comment
Question by:TechGuise
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 5
18 Comments
 
LVL 75
ID: 39944096
Round Up

=-Int(-[YourFieldName])

Round Down:
=Int([YourFieldName])

mx
0
 
LVL 75
ID: 39944099
Be sure to note the  Minus signs :-)
0
 

Author Comment

by:TechGuise
ID: 39944107
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 75
ID: 39944120
yep.
Guaranteed to work in all case.
Most other schemes fail at some point.

mx
0
 

Author Comment

by:TechGuise
ID: 39944125
Are you sure this will take it to the "NEXT EVEN NUMBER"  (like 2,4,6,8)
0
 

Author Comment

by:TechGuise
ID: 39944128
Has something to do with the way the GLASS INDUSTRY charges for cutting glass
0
 
LVL 7

Assisted Solution

by:COACHMAN99
COACHMAN99 earned 250 total points
ID: 39944158
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
 
LVL 75
ID: 39944164
Sorry ... I missed 'EVEN' ...
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 39944177
This should work"

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

mx
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39944179
looks much more elegant :-)
0
 

Author Comment

by:TechGuise
ID: 39944182
You guys are awesome!   Both worked great.  Thanks!!
0
 

Author Comment

by:TechGuise
ID: 39944187
Can I ask what MOD 2 does?
0
 
LVL 7

Expert Comment

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

Author Comment

by:TechGuise
ID: 39944208
Thank You!
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39944218
you're welcome!
0
 
LVL 75
ID: 39944574
Thanks to Gustav Brock for the elegant Round Up/Down functions .... :-)

mx
0
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39945581
hear! hear!   (mine was very 'in-elegant') :-)
0
 
LVL 75
ID: 39945784
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question