ON ERROR RESUME NEXT

D

D.S.

First post not showing up on board, will try posting again.


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?

dim dteDate as Date

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

Anders S

The following code works for me. Nothing changed, just added a MsgBox.

Sub test354()
Dim dteDate As Date

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
MsgBox "Date OK"
End Sub

Regards
Anders Silven

'---------------------------

"D.S." <[email protected]> skrev i meddelandet First post not showing up on board, will try posting again.


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?

dim dteDate as Date

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

D.S.

Yep, works for me to if I run this as a separate procedure, but when this code is within another procedure, it hangs on me every time.

D.S


The following code works for me. Nothing changed, just added a MsgBox.

Sub test354()
Dim dteDate As Date

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
MsgBox "Date OK"
End Sub

Regards
Anders Silven

'---------------------------

"D.S." <[email protected]> skrev i meddelandet First post not showing up on board, will try posting again.


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?

dim dteDate as Date

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

losmac

Your code with my comments

dim dteDate as Date

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 'here, You want to exit or go back to the
begining?
End If
On Error GoTo 0 'here is no error, You already exit


'==========================================
Here is corect code:

Dim dteDate As Date

showAgain: 'start here on error
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
Err.Clear 'clear error
GoTo showAgain 'go to begining
End If


Sorry for language....
-----Original Message-----
First post not showing up on board, will try posting again.


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?
 
A

Anders S

D.S.,

Could it be that there is "active" error handler in a calling procedure? Read VBA Help on On Error, it might give you some clues.

Regards,
Anders Silven

-------------------------

"D.S." <[email protected]> skrev i meddelandet Yep, works for me to if I run this as a separate procedure, but when this code is within another procedure, it hangs on me every time.

D.S


The following code works for me. Nothing changed, just added a MsgBox.

Sub test354()
Dim dteDate As Date

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
MsgBox "Date OK"
End Sub

Regards
Anders Silven

'---------------------------

"D.S." <[email protected]> skrev i meddelandet First post not showing up on board, will try posting again.


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?

dim dteDate as Date

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

Haldun Alay

Hi,

InputBox returns an empty string when Cancel Button pressed. So the error message that you received, raised by CDate function. When Cancel button pressed, CDate is trying to convert an empty ("") string returned by InputBox to Date and raising an error message.

You need to change your error trapping code. Like following;

Dim dteDate As Date
Dim temp
On Error Resume Next 'turn on error handling
temp = InputBox("Enter ending date for projection", Default:=Date)
If temp = "" Then 'trap error if user clicks the cancel button or leaves empty
Exit Sub
End If
dteDate = CDate(temp)
If Err.Number > 0 Then 'trap error if not a valid date string entered
Err.Clear
Exit Sub
End If

On Error GoTo 0 'reinstate normal error procedures




--
Regards

Haldun Alay

To e-mail me, please remove AT and DOT from my e-mail address.



"D.S." <[email protected]>, iletide sunu yazdi First post not showing up on board, will try posting again.


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?

dim dteDate as Date

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

D.S.

Thank you, that works too. Is there an advantage of one way over the other?

D.S.


"Haldun Alay" <haldunalayATyahooDOTcom> wrote in message
Hi,

InputBox returns an empty string when Cancel Button pressed. So the error
message that you received, raised by CDate function. When Cancel button
pressed, CDate is trying to convert an empty ("") string returned by
InputBox to Date and raising an error message.

You need to change your error trapping code. Like following;

Dim dteDate As Date
Dim temp
On Error Resume Next 'turn on error handling
temp = InputBox("Enter ending date for projection", Default:=Date)
If temp = "" Then 'trap error if user clicks the cancel button or leaves
empty
Exit Sub
End If
dteDate = CDate(temp)
If Err.Number > 0 Then 'trap error if not a valid date string entered
Err.Clear
Exit Sub
End If

On Error GoTo 0 'reinstate normal error procedures




--
Regards

Haldun Alay

To e-mail me, please remove AT and DOT from my e-mail address.



"D.S." <[email protected]>, iletide sunu yazdi
First post not showing up on board, will try posting again.


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?

dim dteDate as Date

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

Haldun Alay

Hi,

The advantage of modified code is, you can handle if user clicks cancel button or leaves empty and later on check if user entered a valid date.


--
Regards

Haldun Alay

To e-mail me, please replace AT and DOT in my e-mail address with the original signs.



"D.S." <[email protected]>, iletide þunu yazdý Thank you, that works too. Is there an advantage of one way over the other?

D.S.


"Haldun Alay" <haldunalayATyahooDOTcom> wrote in message
Hi,

InputBox returns an empty string when Cancel Button pressed. So the error
message that you received, raised by CDate function. When Cancel button
pressed, CDate is trying to convert an empty ("") string returned by
InputBox to Date and raising an error message.

You need to change your error trapping code. Like following;

Dim dteDate As Date
Dim temp
On Error Resume Next 'turn on error handling
temp = InputBox("Enter ending date for projection", Default:=Date)
If temp = "" Then 'trap error if user clicks the cancel button or leaves
empty
Exit Sub
End If
dteDate = CDate(temp)
If Err.Number > 0 Then 'trap error if not a valid date string entered
Err.Clear
Exit Sub
End If

On Error GoTo 0 'reinstate normal error procedures




--
Regards

Haldun Alay

To e-mail me, please remove AT and DOT from my e-mail address.



"D.S." <[email protected]>, iletide sunu yazdi
First post not showing up on board, will try posting again.


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?

dim dteDate as Date

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.
 

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


Top