Password in a Text field

L

Linda

Hi,

I have created a form where it has a text field that is only for IT use. So
when you click on the text box, it asks for a password. The only problem I
am having is that when you enter an incorrect password, it still allows you
to type in the text field. It will come up with a message that you have
entered an incorrect password, you click ok and it returns you to that text
box. But it allows you to start entering instead of asking for the password
again.
Any suggestions?

Thanks
Linda
 
N

Nicholas Scarpinato

Please post the code for the text box (I'm assuming you're using the OnClick
event?), it will be much easier to help you if we can see the code.
 
G

Golfinray

Try this:
Dim stpassword As String
stpassword = inputbox("Enter Your Password")
If stpassword = "areaa" Then
DoCmd.OpenForm "manager a tracking", , , acnornmal
Me.Visible = False
Else: MsgBox "You Entered the wrong password", vbOKOnly
End If
 
L

Linda

Here is the code:
Private Sub Text85_Enter()
Dim Password, Loggin
Password = "Query"
Loggin = InputBox("Enter password")
If Loggin <> Password Then
MsgBox "Sorry wrong password!!"
Else
DoCmd.GoToControl "Text85"
End
End If


End Sub
 
N

Nicholas Scarpinato

Comments inline:

Linda said:
Here is the code:
Private Sub Text85_Enter()
Dim Password, Loggin
Password = "Query"
Loggin = InputBox("Enter password")
If Loggin <> Password Then
MsgBox "Sorry wrong password!!"
Else
DoCmd.GoToControl "Text85"
End
End If


End Sub

It looks like you're really not doing anything. The end is the same result,
it goes back to the textbox, because you're not telling it not to when the
password is incorrect. You need to add a line of code to move the focus away
from that textbox whenever the password is incorrect, something like:

Me![Text83].SetFocus

That way the user has to click back on the box again to get the password
screen. Also, your GoToControl command is pointless, once you've clicked on
the textbox, that control will have the focus. So if the password is correct,
that control will already be selected, which is also why you're having the
problem with the incorrect password.

Personally, I would change that textbox to being disabled, and enabling it
only if the password is correct through an OnClick event:

Private Sub Text85_Click()
Dim Password, Loggin
Password = "Query"
Loggin = InputBox("Enter password")
If Loggin <> Password Then
MsgBox "Sorry wrong password!!"
Else
Me![Text85].Enabled = True
Me![Text85].SetFocus
End If
End Sub


Just remember that you'll have to reset your control to Enabled = False
somewhere else in your code.
 
N

Nicholas Scarpinato

Bah... nevermind, setting it to Enabled = False won't work, the OnClick event
won't fire if the control is disabled. Sorry.

But changing the focus on the form will work for your original code.

Nicholas Scarpinato said:
Comments inline:

Linda said:
Here is the code:
Private Sub Text85_Enter()
Dim Password, Loggin
Password = "Query"
Loggin = InputBox("Enter password")
If Loggin <> Password Then
MsgBox "Sorry wrong password!!"
Else
DoCmd.GoToControl "Text85"
End
End If


End Sub

It looks like you're really not doing anything. The end is the same result,
it goes back to the textbox, because you're not telling it not to when the
password is incorrect. You need to add a line of code to move the focus away
from that textbox whenever the password is incorrect, something like:

Me![Text83].SetFocus

That way the user has to click back on the box again to get the password
screen. Also, your GoToControl command is pointless, once you've clicked on
the textbox, that control will have the focus. So if the password is correct,
that control will already be selected, which is also why you're having the
problem with the incorrect password.

Personally, I would change that textbox to being disabled, and enabling it
only if the password is correct through an OnClick event:

Private Sub Text85_Click()
Dim Password, Loggin
Password = "Query"
Loggin = InputBox("Enter password")
If Loggin <> Password Then
MsgBox "Sorry wrong password!!"
Else
Me![Text85].Enabled = True
Me![Text85].SetFocus
End If
End Sub


Just remember that you'll have to reset your control to Enabled = False
somewhere else in your code.
 
L

Linda

Thanks!! That worked!!!

Nicholas Scarpinato said:
Comments inline:

Linda said:
Here is the code:
Private Sub Text85_Enter()
Dim Password, Loggin
Password = "Query"
Loggin = InputBox("Enter password")
If Loggin <> Password Then
MsgBox "Sorry wrong password!!"
Else
DoCmd.GoToControl "Text85"
End
End If


End Sub

It looks like you're really not doing anything. The end is the same result,
it goes back to the textbox, because you're not telling it not to when the
password is incorrect. You need to add a line of code to move the focus away
from that textbox whenever the password is incorrect, something like:

Me![Text83].SetFocus

That way the user has to click back on the box again to get the password
screen. Also, your GoToControl command is pointless, once you've clicked on
the textbox, that control will have the focus. So if the password is correct,
that control will already be selected, which is also why you're having the
problem with the incorrect password.

Personally, I would change that textbox to being disabled, and enabling it
only if the password is correct through an OnClick event:

Private Sub Text85_Click()
Dim Password, Loggin
Password = "Query"
Loggin = InputBox("Enter password")
If Loggin <> Password Then
MsgBox "Sorry wrong password!!"
Else
Me![Text85].Enabled = True
Me![Text85].SetFocus
End If
End Sub


Just remember that you'll have to reset your control to Enabled = False
somewhere else in your code.
 

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

Similar Threads

Windows 10 W10 password prob. 2
Password Prompt 1
Lock out a user from using a field 2
Text Box Validation Rule 4
Text field in Subform 1
Password text box 2
Trimming problem 2
display password as asterisks - Input mask not working 2

Top