LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default ON ERROR RESUME NEXT

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." , 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." , 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.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill & On Error Resume Next Dandelo Excel Discussion (Misc queries) 2 August 21st 08 07:14 PM
On Error Resume Next problem Jim May Excel Discussion (Misc queries) 14 November 2nd 07 12:27 PM
On error resume next problem freekrill Excel Discussion (Misc queries) 2 December 7th 05 12:51 AM
On Error Resume Next D.S.[_3_] Excel Programming 1 November 28th 03 04:52 PM
On Error Resume Next Mike[_58_] Excel Programming 3 November 23rd 03 05:09 PM


All times are GMT +1. The time now is 12:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"