How do I round a number upwards in a query?

G

Guest

I'm running a query that is returning a number which I would like to round to
the nearest 10, nearest 100, or nearest 1000.
 
A

Arvin Meyer

Benny said:
I'm running a query that is returning a number which I would like to round to
the nearest 10, nearest 100, or nearest 1000.

Try this:

Public Function RndUpN(varIn As Variant, n As Variant) As Long
' Rounds anything up to increments of n
' Converts Nulls, Text, and Negative values to 0
' Arvin Meyer 9/17/1998
On Error Resume Next
If IsNumeric(varIn) Then
RndUpN = varIn \ n
RndUpN = RndUpN * n
If (varIn Mod n) > 0 Then
RndUpN = RndUpN + n
End If
Else
RndUpN = 0
End If
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
G

Guest

Thanks very much for your help.

I'm pretty new to the Access program.

Where and how do I input the Public Function

Does it go into a query or into the SQL view or the onevent

Regards,

benny
 
J

John Vinson

Thanks very much for your help.

I'm pretty new to the Access program.

Where and how do I input the Public Function

Does it go into a query or into the SQL view or the onevent

Put it into a Module; save the module with some name OTHER than the
name of the function (basRound maybe). You can then call the function
from a Query or in the control source of a textbox on a form or
report.

John W. Vinson[MVP]
 

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

Similar Threads

Rounding up! 2
Round to a Multiple 2
Access Round() Function Question 5
Round number subject to it's value 1
Round in Payroll situation 4
MROUND 3
Rounding Numbers 1
Round Function 3

Top