Results 1 to 5 of 5
  1. #1
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24

    Login Form Code

    Hello All,

    I am having an odd problem with my login form for my database. If I select a username and input the correct password it gives me a password invalid message box (as it should if the password were invalid), however, if I make no changes at all to the password I entered and just press the login button again the form works correctly. For some reason it fails on the first attempt at any login, no matter if the password is correct or not. It occurs for every user.

    Here is screenshot of my form (I've blacked out the name of my organization).




    The drop down box is named "cboEmployee" the password text box is named "txtPassword". cboEmployee is row sourced as follows: SELECT [TMID], [Team Member Name] FROM ExtQ_TeamMembers ORDER BY [Team Member Name];

    TMID is the primary key for the TeamMembers table, which is a list of employees. ExtQ_TeamMembers is just a query which combines the first and last name of the employees from the TeamMembers table for display purposes.

    The login button runs the following code when clicked:

    Code:
     
    Private Sub cmdLogin_Click()
    
        'Check to see if data is entered into the UserName combo box
    
        If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
          MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.cboEmployee.SetFocus
            Exit Sub
        End If
    
        'Check to see if data is entered into the password box
    
        If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
          MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
            Exit Sub
        End If
    
        'Check value of password in tblEmployees to see if this
        'matches value chosen in combo box
    
        If md5(Nz(Me.txtPassword.Value, "None")) = DLookup("Password", "TeamMembers", "[TMID]=" & Me.cboEmployee.Value) Then
    
            'Close logon form and open splash screen
    
            DoCmd.Close acForm, "GUI_LoginDialog", acSaveNo
            DoCmd.OpenForm "GUI_Home"
    
        Else
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                "Invalid Entry!"
            Me.txtPassword.SetFocus
        End If
    
        'If User Enters incorrect password 3 times database will shutdown
    
        intLogonAttempts = intLogonAttempts + 1
        If intLogonAttempts > 3 Then
          MsgBox "You do not have access to this database.Please contact admin.", _
                   vbCritical, "Restricted Access!"
            Application.Quit
        End If
    End Sub
    Again the weird thing is that on the first attempt I always receive a "Password Invalid" message despite being certain that the password entered is correct. Furthermore this doesn't happen on the second attempt, even if I leave txtPassword untouched and just re-click "Login"

    Any help you could provide me with would be great appreciated. I am sure I am just missing some simple error in my code but I have been staring at it for quite a while now.

    Thanks!

    Paddon

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Maybe try a form requery before you do all your checks? Or maybe on the lost focus of the password text box do a form.requery.

  3. #3
    paddon is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    24
    Good idea. I too thought something must not be updating before the checks take place but alas it did not work.

    I tried both putting a Requery on lostFocus and Docmd.Requery before the checks in the Login OnClick code.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you single stepped this code to see what the values are during the 1st pass?

  5. #5
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Anyone come up with a solution to this yet?

    I fiddled around a bit and came up with a similar option. If you want to just use one table to store usernames and passwords this works. Obviously you will then need to create a form to allow the user to change their password if so desired.

    Code:
    Private Sub Command8_Click()
    'Check to see if data is entered into the UserName combo box
        If IsNull(Me.CboUN) Or Me.CboUN = "" Then
          MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.CboUN.SetFocus
            Exit Sub
        End If
        'Check to see if data is entered into the password box
        If IsNull(Me.txtPassWord) Or Me.txtPassWord = "" Then
          MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassWord.SetFocus
            Exit Sub
        End If
        'Check value of password in tblEmployees to see if this
        'matches value chosen in combo box
        If Me.txtPassWord.Value = DLookup("[Password]", "tblUNandPW", "[UserName]= '" & Me.CboUN.Value & "'") Then
            'Close logon form and open splash screen
            DoCmd.Close ' acForm, "frmLogin", acSaveNo
            DoCmd.OpenForm "frmSupervisors"
        Else
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                "Invalid Entry!"
            Me.txtPassWord.SetFocus
        End If
        'If User Enters incorrect password 3 times database will shutdown
        intLogonAttempts = intLogonAttempts + 1
        If intLogonAttempts > 3 Then
          MsgBox "You do not have access to this database.Please contact admin.", _
                   vbCritical, "Restricted Access!"
            Application.Quit
        End If
    End Sub
    Last edited by Desstro; 04-09-2011 at 01:08 PM.

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

Similar Threads

  1. Login form plus filter
    By bjelinski in forum Forms
    Replies: 1
    Last Post: 11-29-2010, 04:34 AM
  2. Login Form
    By Kookai in forum Access
    Replies: 3
    Last Post: 10-18-2010, 04:23 PM
  3. Login/Password Code not working
    By eww in forum Programming
    Replies: 3
    Last Post: 09-21-2010, 10:49 AM
  4. Login form register
    By isnpms in forum Security
    Replies: 1
    Last Post: 08-01-2010, 10:30 PM
  5. Access login form help
    By Tempuser in forum Forms
    Replies: 8
    Last Post: 09-10-2009, 06:55 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