Results 1 to 3 of 3
  1. #1
    oldlearner is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2015
    Posts
    31

    Login form using 2 text boxes allows Login after adding just Employee Name

    Hi all - I am unable to identify why my login screen allows Login and access to Main form after just typing in a correct employee name. It simply bypasses the need for the password to be added. Can anyone identify anything obvious that I am missing from the code below please.

    Option Compare Database
    Option Explicit
    Private Sub btnLogin_Click()
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("tblEmployee", dbOpenSnapshot, dbReadOnly)

    rs.FindFirst "EmployeeName='" & Me.txtUserName & "'"

    If rs.NoMatch = True Then
    Me.lblwronguser.Visible = True
    Me.txtUserName.SetFocus
    Exit Sub
    End If
    Me.lblwronguser.Visible = False

    If rs!Password <> Me.txtPassword Then


    Me.lblWrongPass.Visible = True
    Me.txtPassword.SetFocus
    Exit Sub
    End If
    Me.lblWrongPass.Visible = False
    DoCmd.OpenForm "FrmMain"
    DoCmd.Close acForm, Me.Name

    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would set a breakpoint and step through the code. You can check what values are being returned to the test.

    http://www.baldyweb.com/Debugging.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    I didn't test it but, I think that if the txtPassword is Null, rs!Password <> Me.txtPassword is False.

    Try it as folows:
    Code:
    If Not IsNull(Me.txtPassword) Then
        If rs!Password = Me.txtPassword Then
            Me.lblWrongPass.Visible = False
            DoCmd.OpenForm "FrmMain"
            DoCmd.Close acForm, Me.Name
            Exit Sub
        End If
    End If
    Me.lblWrongPass.Visible = True
    Me.txtPassword.SetFocus

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-17-2015, 10:59 AM
  2. Replies: 9
    Last Post: 06-02-2014, 08:10 AM
  3. Replies: 11
    Last Post: 06-21-2012, 02:18 AM
  4. Replies: 4
    Last Post: 05-29-2012, 01:32 PM
  5. Login form with nt login
    By hitesh_asrani_j in forum Forms
    Replies: 6
    Last Post: 09-22-2011, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums