Results 1 to 3 of 3
  1. #1
    papa yaw is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    4

    Login form not working properly

    The login form says access denied to everything entered even if the data entered correspondings with the data in the table. The complete code is shown below.

    Option Compare Database
    Option Explicit
    Private Sub Login_Click()
    Static count As Integer
    'Verify if data is entered in the username box
    If IsNull(Me.EmployeeId) Or Me.EmployeeId = "" Then
    MsgBox "Please enter a username.", vbOKOnly, "Required Data"
    Me.EmployeeId.SetFocus
    Exit Sub
    End If


    'Verify if data is entered in the password box
    If IsNull(Me.Password) Or Me.Password = "" Then
    MsgBox "Please enter a Password.", vbOKOnly, "Required Data"
    Me.Password.SetFocus
    Exit Sub
    End If
    EmployeeId = Nz(DLookup("strEmployeeid", "tblEmployee", "StrEmployeeId='" & Me.EmployeeId & "'"), "")
    Password = Nz(DLookup("strPassword", "tblEmployee", "StrPassword='" & Me.Password & "'"), "")
    If Me.EmployeeId = "strEmployeeId" And Me.Password = "strPassword" Then
    MsgBox "Access Granted", vbInformation, "Logging in....."
    DoCmd.Close
    DoCmd.OpenForm "Menu"
    Else
    MsgBox "Access Denied"
    count = count + 1
    If count = 3 Then
    MsgBox "You have failed to login on three tries", vbCritical, "Exiting...."
    DoCmd.CloseDatabase
    End If
    End If
    End Sub

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    check your code for the words in red :

    EmployeeId = Nz(DLookup("strEmployeeid", "tblEmployee", "StrEmployeeId='" & Me.EmployeeId & "'"), "")
    Password = Nz(DLookup("strPassword", "tblEmployee", "StrPassword='" & Me.Password & "'"), "")
    If Me.EmployeeId = "strEmployeeId" And Me.Password = "strPassword" Then
    Are the field names and variables correct ? Should it be If Me.EmployeeId = EmployeeId And Me.Password = Password Then

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    These lines
    Code:
    EmployeeId = Nz(DLookup("strEmployeeid", "tblEmployee", "StrEmployeeId='" & Me.EmployeeId & "'"), "")
    Password = Nz(DLookup("strPassword", "tblEmployee", "StrPassword='" & Me.Password & "'"), "")

    really make no sense to me! It appears that you're using Variables (EmployeeID and Password) that have the same names as Controls on your Form, and after that I simply have no idea!

    At any rate, I ran up a db with your Field and Control names, and the following accomplishes all of your stated goals:
    Code:
    Private Sub Login_Click()
    
    Static count As Integer
    
    'Verify if data is entered in the username box
    If IsNull(Me.EmployeeID) Or Me.EmployeeID = "" Then
     MsgBox "Please enter a username.", vbOKOnly, "Required Data"
     Me.EmployeeID.SetFocus
     Exit Sub
    End If
    
    'Verify if data is entered in the password box
    If IsNull(Me.Password) Or Me.Password = "" Then
     MsgBox "Please enter a Password.", vbOKOnly, "Required Data"
     Me.Password.SetFocus
     Exit Sub
    End If
    
    If DCount("*", "tblEmployee", "strEmployeeId & strPassword = '" & Me.EmployeeID & Me.Password & "'") > 0 Then
    
     MsgBox "Access Granted", vbInformation, "Logging in....."
     DoCmd.Close
     DoCmd.OpenForm "Menu"
    
    Else
    
     MsgBox "Access Denied"
     count = count + 1
     If count = 3 Then
      MsgBox "You have failed to login on three tries", vbCritical, "Exiting...."
     DoCmd.CloseDatabase
    
    End If
    
    End If
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Login form is not working properly
    By papa yaw in forum Forms
    Replies: 1
    Last Post: 12-19-2012, 05:25 PM
  2. Update Query Not Working Properly !
    By hamxa7 in forum Queries
    Replies: 3
    Last Post: 09-20-2012, 04:58 PM
  3. Login form code not working
    By dharmacloud in forum Forms
    Replies: 11
    Last Post: 08-22-2011, 03:08 PM
  4. Delete SQL statement not working properly
    By Alexandre Cote in forum Programming
    Replies: 3
    Last Post: 10-18-2010, 12:56 PM
  5. Query on chart not working properly!
    By Sim_ in forum Queries
    Replies: 0
    Last Post: 10-28-2009, 09:38 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