ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   On Error Resume Next (https://www.excelbanter.com/excel-programming/283864-error-resume-next.html)

D.S.[_3_]

On Error Resume Next
 
Error handling will not work if input box "Cancel" button is selected. I will get an error message, error #13, < Type Mismatch . What's going on here?

On Error Resume Next 'turn on error handling
dteDate = CDate(InputBox("Enter ending date for projection", Default:=Date))
If Err.Number 0 Then 'trap error if user clicks the cancel button
Exit Sub
End If
On Error GoTo 0 'reinstate normal error procedures


D.S.


Michael[_20_]

On Error Resume Next
 
Clicking the Cancel button does not raise an error in and
of itself, it returns a zero length string. The error is
occurring because you are trying to store a zero length
string in a Date variable. Instead, try this:

strInput = InputBox("Enter the Date", Default:=Date)
If strInput < "" Then
dteDate = CDate(strInput)
Else
MsgBox "No Date Selected..."
<jump to exit routine
End If

Mike.

-----Original Message-----
Error handling will not work if input box "Cancel" button

is selected. I will get an error message, error #13, <
Type Mismatch . What's going on here?

On Error Resume Next 'turn on error handling
dteDate = CDate(InputBox("Enter ending date for

projection", Default:=Date))
If Err.Number 0 Then 'trap error if user clicks the

cancel button
Exit Sub
End If
On Error GoTo 0 'reinstate normal error procedures


D.S.



All times are GMT +1. The time now is 08:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com