Login button execution - After Pwd is entered (1 Viewer)

Nagesh

Member
Local time
Today, 15:08
Joined
May 10, 2020
Messages
31
I am creating a Login form and need to call login button after the user has entered the password and hit 'enter' key.
I am aware of the option, where in the button 'default' parameter is set as 'yes'.

However, in case the button default value is set to 'yes', then, after the user enters the username and hit enter, even before entering the password, the 'on click' procedure is executed.
My requirement is, to only execute the on-click procedure after the password field is keyed in and 'enter' key is pressed.

Is there any way to achieve this?
 

Attachments

  • loginForm.JPG
    loginForm.JPG
    21.1 KB · Views: 86

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:08
Joined
May 7, 2009
Messages
19,175
don't set the default button to Yes.
 

Nagesh

Member
Local time
Today, 15:08
Joined
May 10, 2020
Messages
31
don't set the default button to Yes.
In that case, based on the 'tab stop', the focus will be on the login button, but does not get executed, until the user hits enter key again when the focus is on the login button.
 

KitaYama

Well-known member
Local time
Today, 21:08
Joined
Jan 6, 2022
Messages
1,490
It may not be the correct way of achieving your requirements, but if it was me, I would set the button as the default button and add this to the top of onClick event of the button.

Rich (BB code):
    If Password & "" = "" Then
        Password.SetFocus
        End
    Elseif UserID & "" = "" Then
        UserID.SetFocus
        End
    End If
 
Last edited:

Nagesh

Member
Local time
Today, 15:08
Joined
May 10, 2020
Messages
31
It may not be the correct way of achieving your requirements, but if it was me, I would set the button as the default button and add this to the top of onClick event of the button.

Rich (BB code):
    If Password & "" = "" Then
        Password.SetFocus
        End
    Elseif UserID & "" = "" Then
        UserID.SetFocus
        End
    End If
Ok this could work
I will add 'Exit sub' after each if / elseif criteria;
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:08
Joined
Sep 21, 2011
Messages
14,051
Disable the button until a password entry exists?
 

Nagesh

Member
Local time
Today, 15:08
Joined
May 10, 2020
Messages
31
Disable the button until a password entry exists?
This may not b required
Constant check on the fields, monitoring user activity is not required.
I believe adding the code indicated by KitaYama will do the job
An 'Exit sub' can be added after each if criteria


Code:
    If Password & "" = "" Then
        Password.SetFocus
        Exit sub
    Elseif UserID & "" = "" Then
        UserID.SetFocus
        Exit sub
    End If
 

KitaYama

Well-known member
Local time
Today, 21:08
Joined
Jan 6, 2022
Messages
1,490
An 'Exit sub' can be added after each if criteria
End terminates the execution of code. You don't need both End & Exit Sub,
Only one of them will do the job. If you add "Exit Sub" , then delete "End".
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:08
Joined
Feb 19, 2002
Messages
42,981
You spend too much time with web pages. I would never save a default password. Also, if anyone can use the app, you don't need a login at all.

Just use Environ("UserName") if you want to capture the name of the user who opened the database.

When I use logins in my applications, it is because I want to control what the user does. Being loosey goosey with the login defeats that requirement.

Do you have to control access to certain functionality or forms/reports? If so, you need more than just a login. Here is a basic example. It uses four options (View, add, change, delete) with values of 0-9 and assigns them to the user and then to each main form or menu item. The sample also includes a custom switchboard based on the idea of the original Access switchboard but more flexible. It takes a little thought and some trial and error to come up with something that you can manage. Typically, high numbers provide more access than low numbers. The opening login form shows two userID/password combos so you can see the effect. Obviously, your version won't have the test userid/password's displayed on the form:)

 

Users who are viewing this thread

Top Bottom