Thread
:
Inputbox and cancel button
View Single Post
#
2
Posted to microsoft.public.excel.programming
JE McGimpsey
external usenet poster
Posts: 4,624
Inputbox and cancel button
take a look at the Inputbox method in VBA Help. If the user click
Cancel, the value False is returned, which the assignment operator
coerces to a string.
Try this instead:
Const Msg1 As String = "Enter today's date"
Const Msg2 As String = "You did not enter a valid date." & _
vbNewLine & "Please enter today's date"
Dim UInput As Variant
Dim bLoop As Boolean
Do
UInput = Application.InputBox( _
Prompt:=IIf(bLoop, Msg2, Msg1), _
Default:=Date)
If UInput = False Then Exit Sub
bLoop = True
Loop Until IsDate(UInput)
n article ,
(Uddinj1) wrote:
Hi All,
I am rather confused as to why the following macro does not work properly.
The
problem is when the user presses the cancel button without entering anything
in
the Inputbox it starts looping! However, if the user presses OK without
entering anything in the Inputbox then it exits! Can you see why. Thanks for
your help.
Dim UInput as string
Dim Msg as string
Msg = "Enter todays date"
Do
UInput = Application.inputbox(Msg)
If UInput = "" then Exit Sub
If Isdate(UInput) then
Msgbox "Thank You"
Exit Do
End if
Msg = "You did not enter a date"
Msg = Msg & vbNewLine
Msg = Msg & "Enter todays date"
Loop
Regards
UJ
Reply With Quote
JE McGimpsey
View Public Profile
Find all posts by JE McGimpsey