On Error Resume Next

D

D.S.

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.
 
M

Michael

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ON ERROR RESUME NEXT 7
writing excel data into word document 1
On error resume next 2
Copy filtered data to sheet 2 1
On error resume next 8
Error Handling construct 11
On Error Resume Next ? 4
On Error Resume Next 3

Top