Input Box Vs Cancel

A

Ardy

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
 
E

Ed from AZ

The difference is simply the use of all caps (FALSE) or Title Case
(False). As you step through your code with F8, you can mouse over
variables and see what they contain. When I moused over newName, it
contained "False", which does not match "FALSE", so it didn't get
caught in your If statement.

I also hope you have an error trap at some point to catch the person
who hits Enter too quickly and gives you "New Student", since that's
your default for the InputBox.

Ed
 
D

Dave Peterson

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

Ardy

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.






--

Dave Peterson- Hide quoted text -

- Show quoted text -

Thanks Guys.....
I Think I will roll out the file as is, But I relly like Dave's
option of not using Application.InputBox. I need to play with this
and make this a bit more bulet proof. as of now there are some holes
in the applet, which I need to work on. I must have to admit it is
really good learning while doing an practical project. My many thanks
to all of you.

Ardy
 
A

Ardy

Thanks Guys.....
I Think I will roll out the file as is, But I relly like Dave's
option of not using Application.InputBox. I need to play with this
and make this a bit more bulet proof. as of now there are some holes
in the applet, which I need to work on. I must have to admit it is
really good learning while doing an practical project. My many thanks
to all of you.

Ardy- Hide quoted text -

- Show quoted text -

Hau guys what happen to the star ratings..........
 

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

Top