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!

Error handling syntax 1

Status
Not open for further replies.

straybullet

IS-IT--Management
Jun 5, 2003
593
0
0
US
Currently using:

Function Ceiling(ByVal iOne As Double, ByVal iTwo As Double)
Ceiling = Excel.WorksheetFunction.Ceiling(iOne, iTwo)
End Function

which works wonderfully - except (there's always the exception isnt there!) when the base price the ceiling function uses is a negative number.

According to Excel, the ceiling function would ordinarily display zero when the result is negative. What would be the proper way to tell Access 2K that when there is an error, to display a zero?

Let them hate - so long as they fear... Lucius Accius
 
The following would work for negatives in the Ceiling function:
Code:
Function Ceiling(ByVal iOne As Double, ByVal iTwo As Double)
On Error GoTo HandleErrors
    Ceiling = Excel.WorksheetFunction.Ceiling(iOne, iTwo)

ExitClean:
    Exit Function

HandleErrors:
    Select Case Err.Number
        [green]' Error: Unable to get the Ceiling property of the WorksheetFunction class
        '   This error is returned when either iOne or iTwo is negative, but not both[/green]
        Case 1004:
            Ceiling = 0
        Case Else:
            MsgBox "Error: " & Err.Description, vbInformation, "Error " & Err.Number
    End Select

    Resume ExitClean
End Function

Hope this helps,
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top