locked
Several questions with Access 2016 RRS feed

  • Question

  • 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.

    Tuesday, October 27, 2020 7:10 PM

All replies

  • With regard to your two points:

    1. Have a look at this example app on my website: Password Login with session login information

    You should find the code does exactly what you want

    2. Make the login form your startup form in Access options. Then add code after successful login to open the other form in your app. Once again, my example app will show you how to do that

    Hope that helps

    Tuesday, October 27, 2020 8:09 PM
  • I don't know what code the Cancel button is firing, but it certainly is not "overwriting" any other code. If you want the form to close when the Cancel button is clicked, then use:

    the Docmd.Close procedure to close the form on the On Click event.

    If you want the login form to automatically open when the file is opened:

    File>>Options>>Current Database>> Display Form (select your login form)

    If you want a different form to open when the login form closes, then use the DoCmd.OpenForm procedure. Enter the code in the login forms On Close Event. That will open another named form when the login form closes.

    Tuesday, October 27, 2020 8:16 PM
  • Kaplan71 –

    You’d do well to follow the advice of Daniel Pineault in the other forum where you posted this question.


    peter n roth - http://PNR1.com, Maybe some useful stuff

    Tuesday, October 27, 2020 8:27 PM
  • Just so people don't double up on their efforts, this question is cross-posted in https://answers.microsoft.com/en-us/msoffice/forum/all/several-questions-with-access-2016/1218e09c-cf44-4c5f-934b-27988b234083

    Daniel Pineault, 2010-2019 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Tuesday, October 27, 2020 8:52 PM
  • Hello --

    I have not made any progress. The code shown below is what I have so far:

    Private Sub Close_Click()
    
    End Sub
    
    Private Sub cmd_cancel_Click()
    
    End Sub
    
    Private Sub cmd_cancel_Exit(Cancel As Integer)
    
    End Sub
    
    Private Sub cmd_login_Click()
    
      Dim db As DAO.Database
      Dim rst As DAO.Recordset
      Dim strSQL As String
     
      If Trim(Me.txt_username.Value & vbNullString) = vbNullString Then
        MsgBox prompt:="Username should not be left blank.", buttons:=vbInformation, title:="Username Required"
        Me.txt_username.SetFocus
        Exit Sub
      End If
     
      If Trim(Me.txt_password.Value & vbNullString) = vbNullString Then
        MsgBox prompt:="Password should not be left blank.", buttons:=vbInformation, title:="Password Required"
        Me.txt_password.SetFocus
        Exit Sub
      End If
     
      'query to check if login details are correct
      strSQL = "SELECT FirstName FROM tbl_login WHERE Username = """ & Me.txt_username.Value & """ AND Password = """ & Me.txt_password.Value & """"
     
      Set db = CurrentDb
      Set rst = db.OpenRecordset(strSQL)
      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
      End If
     
     Set db = Nothing
     Set rst = Nothing
    
    End Sub
    
    Private Sub cmd_login_Exit(Cancel As Integer)
       
    End Sub

    I have not been able to find any of the procedures listed in your response. Could you provide further information?


    • Edited by kaplan71 Wednesday, October 28, 2020 1:09 PM
    Wednesday, October 28, 2020 1:07 PM
  • I had a chance to look at your app, and it does look very good. 

    Is this a case where I would import the accdb file into the existing database?

    Wednesday, October 28, 2020 1:08 PM
  • Hi Kaplan

    it isn't clear who your last two answers were aimed at. Can you please clarify.

    Wednesday, October 28, 2020 2:12 PM
  • Hello --

    I was able to solve both problems. It came down to modifying a couple of settings in the code. 

    Wednesday, October 28, 2020 2:45 PM
  • OK. Did you use my example app code or fix your own?
    Wednesday, October 28, 2020 5:48 PM
  • I ended up fixing my own code. That being said, I had an opportunity to try out your app, and I will be probably go with your approach on a subsequent database project. Quick question: After I create this other database, can I simply input your accdb file into mine to have all tables and associated files in place? 
    Thursday, October 29, 2020 12:56 PM
  • I ended up fixing my own code. That being said, I had an opportunity to try out your app, and I will be probably go with your approach on a subsequent database project. Quick question: After I create this other database, can I simply input your accdb file into mine to have all tables and associated files in place? 

    Congratulations on fixing your code.

    If you import all objects from my example app into your own, it should work without any issues in either 32-bit or 64-bit Access. No additional references are required.

    Of course, you are also free to modify it to suit your own needs

    Thursday, October 29, 2020 2:19 PM
  • https://docs.microsoft.com/en-us/answers/questions/141733/several-questions-with-access-2016.html
    Sunday, November 1, 2020 10:45 AM