Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I eliminate extra key stroke?

Status
Not open for further replies.

pita2

MIS
Jun 27, 2005
16
US
Hi,

I have a login screen to check for valid passwords. It has a password text box, an Ok button, and a Cancel button. It works fine if the user click the Ok button. However, if the user chooses to press the enter key once the password is entered, they have to press the enter key twice before the next form opens up. I would like to eliminate this extra key stroke. But i am not sure which event or property to set. Any suggestions? Please see sample code for the Ok button. Thanks.

Private Sub cmdOk_Click()
If txtPassword.Value = "password" Then
'close the password form and go to antoher form
DoCmd.Close
DoCmd.OpenForm "anotherform", acNormal
Else
MsgBox "Sorry....", vbOKOnly, "Important Information:"
txtPassword.SetFocus
End If
End Sub
 
In the AfterUpdate event of the password text box, call the cmdOK_Click procedure.
 
Thanks for the reply. I tried that. It works if you entered the correct password. But if I entered the incorrect password, it populated the message, but the focus is not being set in the password field. If I have the code txtPassword.SetFocus, shouldn't the password be set correctly? Any ideas why? Thanks in advance!
 
You could verify that the password is correct in the BeforeUpdate event of the password text box. If not, set Cancel to True.
 
Sorry for the confusion. Let me clarify. In the AfterUpdate event of the text box, I called the cmdOK_click procedure. It works fine except the txtPassword.SetFocus. If a person enters an incorrect password, then the focus goes to the Ok button rather than the txtPassword field like it should be. I am not sure why?

Private Sub cmdOk_Click()
If txtPassword.Value = "password" Then
'close the password form and go to antoher form
DoCmd.Close
DoCmd.OpenForm "anotherform", acNormal
Else
MsgBox "Sorry....", vbOKOnly, "Important Information:"
txtPassword.SetFocus
End If
End Sub
 
You may try this:
cmdOK.SetFocus
txtPassword.SetFocus

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
pita2,

If you want the OK button to be automatically clicked when the user hits the Enter key, set the button's Default property to Yes.

Ken S.
 
It works! It puts the cursor in the textbox. One thing though, the user still has to space out the incorrect password and retype it. How can I highligh the incorrect password, and the user can just overtype it? Thanks much!!
 
Eupher,

Your suggestion work exactly the way I wanted. Thank you all for your help!!

You guys are the best!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top