Several questions regarding a login form in Access 2016

%3CLINGO-SUB%20id%3D%22lingo-sub-1824372%22%20slang%3D%22en-US%22%3ESeveral%20questions%20regarding%20a%20login%20form%20in%20Access%202016%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1824372%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%20%E2%80%93%3C%2FP%3E%3CP%3EI%20am%20in%20the%20process%20of%20setting%20up%20user%20logins%20for%20an%20Access%202016%20database.%20The%20article%20that%20I%20am%20using%20to%20accomplish%20this%20task%20is%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.datanumen.com%2Fblogs%2Fhow-to-protect-your-sensitive-data-with-a-login-form-in-access%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fwww.datanumen.com%2Fblogs%2Fhow-to-protect-your-sensitive-data-with-a-login-form-in-access%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFollowing%20the%20procedure%20shown%20in%20the%20article%2C%20I%20have%20created%20a%20login%20table%2C%20and%20associated%20form%20that%20I%20would%20like%20to%20deploy.%20However%2C%20I%20am%20running%20into%20two%20issues%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20The%20Cancel%20button%20on%20the%20login%20form%20does%20not%20work%2C%20and%20although%20I%20have%20the%20code%2C%3CBR%20%2F%3Eevery%20time%20it%20is%20applied%2C%20it%20overwrites%20the%20code%20for%20the%20Login%20button%20on%20the%20same%20form.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20I%20would%20like%20to%20have%20the%20login%20form%20be%20the%20first%20form%20that%20is%20seen%20by%20a%20given%20user.%20After%3CBR%20%2F%3Ethe%20user%20logs%20in%2C%20I%20would%20like%20them%20to%20be%20automatically%20brought%20to%20another%20form.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20this%20be%20done%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1824372%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E2016%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1828618%22%20slang%3D%22en-US%22%3ERe%3A%20Several%20questions%20regarding%20a%20login%20form%20in%20Access%202016%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1828618%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F699575%22%20target%3D%22_blank%22%3E%40Andrew_Kaplan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20realize%20the%20second%20issue%20with%20adding%20a%20%3CSTRONG%3EDoCmd.OpenForm%3C%2FSTRONG%3E%26nbsp%3Bstatement%20to%20the%20Else%20branch%20(I%20added%20only%20the%20last%20part%20of%20the%20cmd_Login_Click%20routine)%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E...%0AIf%20rst.EOF%20Then%0A%20%20%20%20MsgBox%20prompt%3A%3D%22Incorrect%20username%2Fpassword.%20Try%20again.%22%2C%20buttons%3A%3DvbCritical%2C%20title%3A%3D%22Login%20Error%22%0A%20%20%20%20Me.txt_username.SetFocus%0A%20%20Else%0A%20%20%20%20MsgBox%20prompt%3A%3D%22Hello%2C%20%22%20%26amp%3B%20rst.Fields(0).Value%20%26amp%3B%20%22.%22%2C%20buttons%3A%3DvbOKOnly%2C%20title%3A%3D%22Login%20Successful%22%0A%20%20%20%20DoCmd.Close%20acForm%2C%20%22frm_login%22%2C%20acSaveYes%0A%20%20%20%20DoCmd.OpenForm%20%22Name%20of%20the%20Form%20You%20Want%20to%20be%20Opened%22%0A%20%20End%20If%0A%20%0A%20Set%20db%20%3D%20Nothing%0A%20Set%20rst%20%3D%20Nothing%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGood%20luck!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETieme%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

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.