Several questions regarding a login form in Access 2016

Copper Contributor

Hello  –

I am in the process of setting up user logins for an Access 2016 database. The article that I am using to accomplish this task is the following:

 

https://www.datanumen.com/blogs/how-to-protect-your-sensitive-data-with-a-login-form-in-access/

 

Following the procedure shown in the article, I have created a login table, and associated form that I would like to deploy. However, I am running into two issues:

 

1. The Cancel button on the login form does not work, and although I have the code,
every time it is applied, it overwrites the code for the Login button on the same form.

 

2. I would like to have the login form be the first form that is seen by a given user. After
the user logs in, I would like them to be automatically brought to another form.

 

How can this be done?

2 Replies

@Andrew_Kaplan 

You can realize the second issue with adding a DoCmd.OpenForm statement to the Else branch (I added only the last part of the cmd_Login_Click routine):

...
If rst.EOF Then
    MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Login Error"
    Me.txt_username.SetFocus
  Else
    MsgBox prompt:="Hello, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, title:="Login Successful"
    DoCmd.Close acForm, "frm_login", acSaveYes
    DoCmd.OpenForm "Name of the Form You Want to be Opened"
  End If
 
 Set db = Nothing
 Set rst = Nothing

End Sub

 

Good luck!

 

Tieme

 

Hello --

 

That did the trick. 

 

Thanks.