View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Cancel on INPUTBOX macro causes error

What happens if the user actually wants to cancel? It is bad form not to
allow the user a means to escape.

--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in message
...
Actually, I don't want to exit the sub if they've cancelled. I want it to
loop back and ensure that they've entered a date. Otherwise, other parts

of
subsequent code will gack.


"Toppers" wrote in message
...
Barb,
As one of the previous respondents: you omitted the

following
statement after the Inputbox line (which was in the earlier postings):

If SummaryDate = False then exit sub ' User cancelled

FYI: the code posted by JE McGimpsey is "better" than mine in that it
automatically checks for an invalid date e.g 32/1/06 as it set the TYPE
parameter to 1; you might want to refer and change to it.


"Barb Reinhardt" wrote:

I have the following snippet of code (thanks to someone here)

Public SummaryMin As Date
Public SummaryMax As Date
Public SummaryDate As Date

Do
SummaryDate = DateValue(Application.InputBox("Enter Summary

Reporting
Date between " & SummaryMin & " and " & SummaryMax, "Reporting Date",
SummaryMin))
If Not Application.And(SummaryDate = SummaryMin, SummaryDate <=
SummaryMax) Then
MsgBox "Invalid date. Please re-enter"
End If
Loop Until Application.And(SummaryDate = SummaryMin, SummaryDate

<=
SummaryMax)

It works fine unless I cancel. I get a RUNTIME error, type 13.


Thanks,
Barb Reinhardt