'Function Round (n,d) 'Revised
'*****************************************************************
'Accepts: a variant value
'Purpose: converts multiuplace decimal numbers
'Returns: a number "formatted" to d decimal places. I used the 
'	  original Format () designed by Marcus O. M. Grabe 
'	  CIS 100120,1405, but I found that dur to the fact that
'	  Access inherently does not round up when it comes face
'	  to face with a value of 5 (I'd like to meet the genius that
' 	  came up with that one) I had to include the if statements
'	  to add the .001, .0001, etc. to round up if it met
'	  certain criteria, as you can see below. I am by no means an
'	  experienced programmer, so if you have any suggestions, please feel
'	  free to modify this, all I ask is that you let me know, so I can
'	  make the changes myself.
'
'	  	Christopher V. Garcia, CIS 72623,3437
'*****************************************************************
Function Round (n, d)
    If IsNull(n) Or IsNull(d) Then
        Sum = 0
        Round = Sum
    Else
        If d < 0 Then
            d = 0
        Else
            d = Int(d)
        End If
    If d = 2 And Right(Format(n, "#,###.000"), 1) = 5 Then
        Sum = Format(n + .001, "#,###.00")
        Round = Sum
    ElseIf d = 2 Then
        Sum = Format(n, "#,###.00")
        Round = Sum
    ElseIf d = 3 And Right(Format(n, "#,###.0000"), 1) = 5 Then
        Sum = Format(n + .0001, "#,###.000")
        Round = Sum
    ElseIf d = 3 Then
        Sum = Format(n, "#,###.000")
        Round = Sum
    ElseIf d = 4 And Right(Format(n, "#,###.00000"), 1) = 5 Then
        Sum = Format(n + .00001, "#,###.0000")
        Round = Sum
    ElseIf d = 4 Then
        Sum = Format(n, "#,###.0000")
        Round = Sum
    ElseIf d = 0 Then
        Sum = Format(n, "#,###")
        Round = Sum
    End If
    End If
End Function
