Input Box Vs Cancel
Just to add to Ed's explanation...
VBA is case sensitive when you're comparing text (unless you tell the module not
to be).
So "False" is different from "FALSE" is different from "FaLsE"...
And I bet you declared newName as a string--so the boolean False was changed to
the string "False".
I may have used:
dim newName as variant
newname = application.inputbox(...)
if newname = "" _
or newname = False then ' this checks for the boolean false--not a string.
...
But I would have really used Inputbox (without application.inputbox).
dim NewName as string
newname = inputbox(...)
if trim(newname) = "" then
'they canceled
else
'they didn't
end if
I guess I don't see the benefit of using application.inputbox(type:=2) to return
a text string.
Ardy wrote:
On Sep 5, 10:31 am, Ed from AZ wrote:
Change "FALSE" to "False" and it should work.
Ed
On Sep 5, 9:33 am, Ardy wrote:
Hello All:
I have a code that will give me a input box to add name to the list.
newName = Application.InputBox("Type new student name:", "Add
Student", "New Student", Type:=2)
If newName = "" Or newName = "FALSE" Then
Exit Sub
End If
My problem is that the input box has OK, Cancel and the X windows
default close option in top upper right corner. If I add a name and
press OK all is fine. However the cancel and close window option will
create a name called FALSE. How would I make it exit sub once those
to functions are pressed.
Regards
Ardy
Ed:
Great, So Simple..... Could you explain a bit what is the difference
between the two.
--
Dave Peterson
|