ROUNDUP function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to use the ROUNDUP function in Access VB. When I write it in the
procedure behind my command button, it completes the word correctly as
'RoundUp' but it won't run / compile as it comes up with the 'Sub or Function
not found' message box.

RoundUp must be in a library file, but I don't know which one. Can u help?

If not, I guess I'll just have to write a separate function to do it...

Ta

Doug
 
Doug said:
Hi,

I need to use the ROUNDUP function in Access VB. When I write it in
the procedure behind my command button, it completes the word
correctly as 'RoundUp' but it won't run / compile as it comes up with
the 'Sub or Function not found' message box.

RoundUp must be in a library file, but I don't know which one. Can u
help?

If not, I guess I'll just have to write a separate function to do
it...

Access VBA has no built-in equivalent to the Excel ROUNDUP worksheet
function. While you could, if it were really necessary, create an Excel
application object and use it to call the Excel function, it would be
much simpler and more efficient just to write your own version of this
simple function.
 
Doug,

You can try the following. I used .9999 because I needed to roundup pretty
much everything. You can change to .5 or to whatever value you need to round
against.

Hope this helps. - T

Public Function RoundUp(dblnumber As Double) As Double
Dim dblfactor As Double
Dim dblTemp As Double
Dim intDecimals As Integer

intDecimals = 0

dblfactor = 10 ^ intDecimals
dblTemp = dblnumber * dblfactor + 0.9999
' dblTemp = dblnumber * dblfactor + 0.5
RoundUp = Int(dblTemp) / dblfactor

End Function
 
Cheers chaps. Saves me some time!

Doug.

T said:
Doug,

You can try the following. I used .9999 because I needed to roundup pretty
much everything. You can change to .5 or to whatever value you need to round
against.

Hope this helps. - T

Public Function RoundUp(dblnumber As Double) As Double
Dim dblfactor As Double
Dim dblTemp As Double
Dim intDecimals As Integer

intDecimals = 0

dblfactor = 10 ^ intDecimals
dblTemp = dblnumber * dblfactor + 0.9999
' dblTemp = dblnumber * dblfactor + 0.5
RoundUp = Int(dblTemp) / dblfactor

End Function
 
Access does not have a roundup function but you could use this code.
Public Function Roundup(dblNumber As Double, varRoundAmount As Double, _
Optional varUp As Variant) As Double

Dim dblTemp As Double
Dim lngTemp As Long

dblTemp = dblNumber / varRoundAmount
lngTemp = CLng(dblTemp)

If lngTemp = dblTemp Then
Roundup = dblNumber
Else
If IsMissing(varUp) Then
' round down
dblTemp = lngTemp
Else
' round up
dblTemp = lngTemp + 1
End If
Roundup = dblTemp * varRoundAmount
End If


End Function
 
Back
Top