Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Roundup Function 3

Status
Not open for further replies.

Umbane

IS-IT--Management
Jul 20, 2000
44
0
0
ZA
In Excell, using roundup produces the following results:
ROUNDUP(45.2,-1)=50
ROUNDUP(45.2,0)=46

My 1st question is: Is there a function in access that will produce the same result?
Secondly, if not, how to go about writing the code?

Thanks for now
 
You can use a combination of functions...like

CDbl(Format(myInt, "#,##0"))

The Format function returns the value you specify in the format you specify
Format(YourValue,YourFormat)

and works like...
Format(4.6798,"#,##0") = "5"

the CDbl function returns a value specified in Type Double
CDbl(YourValue)

and works like
CDbl("5") = 5

So - CDbl(Format(4.6798,"#,##0")) = 5 and function looks like:

Function RoundMyVal(MyVal as Double) as Double
RoundMyVal = CDbl(Format(4.6798,"#,##0"))
End Function

Hope this helps. I am sure there is probably shorter way of doing it, but that works for me.

 
Try....

Public Function RoundUp(Number As Double, Num_Digits As Integer) As Double

'Set up variables
Dim dblNumNum_Digits As Double
Dim lngNumNum_Digits As Long

'Move decimal point such that int will perform at correct level
dblNumNum_Digits = Number * (10 ^ Num_Digits)

'Integerise
lngNumNum_Digits = Int(dblNumNum_Digits)

'Roundup
intNumNum_Digits = intNumNum_Digits + 1

'Return result, moving decimal point back
RoundUp = intNumNum_Digits / (10 ^ Num_Digits)

End Function

Craig
 
If you use a function in Excel then you can use that same function in Access, you just have to do a few simple steps.
[ul][li]Install the Microsoft Excel 9.0 Object Library (note your number might not be 9.0, it just depends on your version of Access) If you don't know how to install a library go to your Microsoft Visual Basic window (ALT - F11), then goto Tools, References.[/li]
[li]Next create a module or use an existing module that you store your functions in.[/li]
[li]Create whatever functions that you want to use from Excel, for example the RoundUp function from Excel would be created like this:[/li][/ul]
Code:
Function RoundUp(arg1 As Double, arg2 As Double) As Double
RoundUp = Excel.WorksheetFunction.RoundUp(arg1, arg2)
End Function

Now you should be albe to call this function from anywhere in your database just like you do in excel.

Hope this helps
Dan
 
Thanks for the help guys, Dan, your'e a genius.
 
You should be aware that use of 'foregin' functions may cause some problems in multiuser (or copying) of the .mdb to other locations

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top