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
Solved

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

Posted on 2014-03-20
18
2,915 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
  • 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
corrupt Databases 9 63
DateAdd every year from Jun 3 24
90 days before current date 12 30
How open a file when clicking on a text field 7 19
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

809 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