ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Doing nothing when pressing Cancel on InputBox (https://www.excelbanter.com/excel-programming/402106-doing-nothing-when-pressing-cancel-inputbox.html)

Memento

Doing nothing when pressing Cancel on InputBox
 
Hello Guys, a rather simple thing, yet i don't know why it does not work:

the code asks simply for a password, if the password is correct, perform the
code. Or if the user typed nothing in the inputbox, or pressed Cancel, do
nothing. If the password is wrong, give message "wrong password".


response = InputBox("give password: ") = "abcdefg"
If response = vbNullString Then Exit Sub 'This code should exit the sub if
no typing or pressed on Cancel button
If response = "abcdefg" Then
'Code to execute Else
MsgBox "password incorrect!", vbCritical
End If

this doesn't work as it should, any ideas what's wrong?

Thanks in advance.


Per Jessen

Doing nothing when pressing Cancel on InputBox
 

"Memento" skrev i en meddelelse
...
Hello Guys, a rather simple thing, yet i don't know why it does not work:

the code asks simply for a password, if the password is correct, perform
the
code. Or if the user typed nothing in the inputbox, or pressed Cancel, do
nothing. If the password is wrong, give message "wrong password".


response = InputBox("give password: ") = "abcdefg"
If response = vbNullString Then Exit Sub 'This code should exit the sub if
no typing or pressed on Cancel button
If response = "abcdefg" Then
'Code to execute Else
MsgBox "password incorrect!", vbCritical
End If

this doesn't work as it should, any ideas what's wrong?

Thanks in advance.


Try this:

response = InputBox("give password: ") = "abcdefg"
If response = False Then Exit Sub 'This code should exit the sub if no
typing or pressed on Cancel button
If response = "abcdefg" Then
'Code to execute
Else
MsgBox "password incorrect!", vbCritical
End If

Regards,

Per



Jay

Doing nothing when pressing Cancel on InputBox
 
Hi Memento -

response = InputBox("give password: ") '= "abcdefg"
'Following code should exit the sub if no typing Cancel
If response = vbNullString Then Exit Sub
If response = "abcdefg" Then
'Code to execute
MsgBox "Password Correct !", vbInformation
Else
MsgBox "password incorrect!", vbCritical
End If

---
Jay

"Memento" wrote:

Hello Guys, a rather simple thing, yet i don't know why it does not work:

the code asks simply for a password, if the password is correct, perform the
code. Or if the user typed nothing in the inputbox, or pressed Cancel, do
nothing. If the password is wrong, give message "wrong password".


response = InputBox("give password: ") = "abcdefg"
If response = vbNullString Then Exit Sub 'This code should exit the sub if
no typing or pressed on Cancel button
If response = "abcdefg" Then
'Code to execute Else
MsgBox "password incorrect!", vbCritical
End If

this doesn't work as it should, any ideas what's wrong?

Thanks in advance.


Mike H

Doing nothing when pressing Cancel on InputBox
 
Maybe this:--

Sub getpass()
response = InputBox("give password: ")
If response = "" Then Exit Sub
If response = "abcdefg" Then
MsgBox "correct password entered"
Else
MsgBox "password incorrect!", vbCritical
End If

End Sub

Mike

"Memento" wrote:

Hello Guys, a rather simple thing, yet i don't know why it does not work:

the code asks simply for a password, if the password is correct, perform the
code. Or if the user typed nothing in the inputbox, or pressed Cancel, do
nothing. If the password is wrong, give message "wrong password".


response = InputBox("give password: ") = "abcdefg"
If response = vbNullString Then Exit Sub 'This code should exit the sub if
no typing or pressed on Cancel button
If response = "abcdefg" Then
'Code to execute Else
MsgBox "password incorrect!", vbCritical
End If

this doesn't work as it should, any ideas what's wrong?

Thanks in advance.


Gaurav Kothari

Doing nothing when pressing Cancel on InputBox
 
You can use strptr funtion ...........

response = InputBox("Enter password")
If StrPtr(pq) < 0 Then
'Code to execute
Else
MsgBox "password incorrect!", vbCritical
End If
Exit Sub

:) have a great time

Gaurav Kothari

"Memento" wrote:

Hello Guys, a rather simple thing, yet i don't know why it does not work:

the code asks simply for a password, if the password is correct, perform the
code. Or if the user typed nothing in the inputbox, or pressed Cancel, do
nothing. If the password is wrong, give message "wrong password".


response = InputBox("give password: ") = "abcdefg"
If response = vbNullString Then Exit Sub 'This code should exit the sub if
no typing or pressed on Cancel button
If response = "abcdefg" Then
'Code to execute Else
MsgBox "password incorrect!", vbCritical
End If

this doesn't work as it should, any ideas what's wrong?

Thanks in advance.



All times are GMT +1. The time now is 10:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com