Password Proctecting field with password

Marie13

New member
Local time
Today, 10:09
Joined
Oct 24, 2014
Messages
2
Afternoon

i have found a code that brings up a box when tab or clicking in to a box for editing as below:-

Dim strPassword As String

If InputBox("Please enter the password:") <> strPassword Then
SomeOtherControl.SetFocus
TextBox1.Locked = True
End If

its just that need to add a password as well, i have tried to put this in between the <> but this does not work. can you help? i would like a message to say incorrect password as well if possable.

thanks

marie
 
Hi Marie!

strPassword is empty!
You compare the result of the Inputbox with nothing!

You did not assign any value to the variable strPassword.

What about this:
Code:
 Dim strPassword As String
 Dim strInputPW as string
  
 strPassword= retrieve from a table field e.g. or somewhere else
 strInputPW=InputBox("Please enter the password:") 
  
 If strInputPW <> strPassword Then
SomeOtherControl.SetFocus
TextBox1.Locked = True
End If
should work
 
Thanks for that.

that does work by brings the box up twice. also would like to add a comment to say incorrect password as well.

thanks

marie
 
the problem with inputbox is that you cannot mask the characters, so the password is not entered secretly (unless MS changed it recently).

If you want a secretly typed password form, you need to roll your own, which is a bit of a pain.
 
Try this:

Code:
 Dim strPassword As String
 Dim strInputPW as string
  
 strPassword= "test"    
 ' or retrieve yr Password from a table field e.g. or somewhere else
 strInputPW=InputBox("Please enter the password:") 
  
 If strInputPW <> strPassword Then
 Msgbox "Password does not match", vbokonly+vbcritical, "Incorrect Password"
TextBox1.Locked = True
Someothercontrol.setcfocus
 else 
 ..do something else
End If

But again, you want to compare your Password entered in the Inputbox with an existing PW, so you have to get to correct Password from somewhere, otherwise you cannot compare it to the PW from the Inputbox!!

You would compare
If "" <> "test" or with other words: if nothing <> "test"
 

Users who are viewing this thread

Back
Top Bottom