Doing nothing when pressing Cancel on InputBox

M

Memento

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

Per Jessen

Memento said:
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
 
J

Jay

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
 
M

Mike H

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
 
G

Gaurav Kothari

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
 

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