Press Enter after password entry to gain access.

Damob9K

Trainee numpty
Local time
Today, 18:13
Joined
Apr 12, 2014
Messages
69
Hi all, back again ! I have had to put my DB on hold while working on another project.

Just trying to finish things off now.

I couldn't really find the right words to describe what I want in the title !

So.. what I have is a password entry popup, it's very simple and there is only one password, so it's coded into the form.
There is an unbound text box for the password, set with the password input mask.
An OK button and an Exit button.
The OK button has this code on the 'On Click'

Code:
Private Sub cmdOK_Click()
If IsNull(passwordentry) Then
passwordentry = "*"
End If

Dim PW As String
PW = "whatever"

If PW <> passwordentry Then
 
         MsgBox "Wrong Password", vbCritical, ""
         Me.passwordentry.Value = ""
         Me.passwordentry.SetFocus
         
Else
DoCmd.Close acForm, "PasswordEntry"
DoCmd.OpenForm "MainMenuForm"

End If

End Sub

Now what I want it to do is automatically move to the OK button when the correct password is entered, so that you can just hit Enter.
Currently you either have to press the OK button with your mouse, or hit Enter to move to the OK button and then press Enter again to activate it.

Sounds a bit fussy but I just want it to at least seem a bit more professional :)
Any help highly appreciated.

D.
 
hi Damo

Whilst this is achievable using the On_Change event, it is NOT a good idea. Whilst your database may not hold the defence secrets of a nation (or my secret chocolate cake reipe - it doesn't, does it?:confused:) you make it easier for 'hackers' and other mischief makers. They can just hit your input box with strings until the OK button is auto selected and hey presto, they are in.

It is good to see you want it to look more professional. The way i do log in forms is with NO OK button. Run your code to check the password in the textbox After_update event.
 
Hi Isskint,

I sort of understand what your saying, but ..

The OK button is the where the password verification happens, so unless there is some access quirk that I'm not aware of (there will be many) would it not matter how many times someone entered random letters ?

Also, no it's not holding anything particularly secret, it's out ICT asset data and is stored on a network share that only certain people can get access to, but we don't want all of them to be able to go into the database just really to protect it's integrity. I'm not supposed to say who I work for, but it's within a GOV network, so pretty secure from the outside world !

I suppose to simplify the issue, what I want to do is to make it auto tab to the OK button as soon as the correct amount of characters are entered, I already have the tab order set so it goes to the OK button on tab or enter, but just want it to do this automatically.

Cheers

D.
 
Hi Damo

OK issues of security aside;
  1. No OK Button option: Move the code you have in the cmdOK_Click event and put it under the password textbox's After_Update event
  2. Moving focus to the OK button after x character are typed: In the textbox's change event put the code
    Code:
    If Len(Me.Text0.Text) = x Then Me.cmdOK.SetFocus
    where x is the length of the password
 
Hi Isskintm,

Thanks a zillion !!

I did actually modify it a bit as your method was automatically activating the OK button and then throwing up a error message regarding the setfocus (i think because the form had closed)

So I put the password check code back into the cmdOK_Click event and kept the If Len(Me.Text0.Text) = x Then Me.cmdOK.SetFocus in the text input box, and it works absolutely perfectly !!

This is great as I have a whole bunch of forms that I really wanted to be able to use this method, so now I know how to :D

Now to fix my last major hurdle : merge data from a form that gets half it's data from one table, the rest from unbound text boxes and then add this to a new record in a new table using the SQL INSERT INTO statement ... phew !! getting there ;)
 

Users who are viewing this thread

Back
Top Bottom