Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43

    Login ID Code for Access 2007 not working

    Hi,



    I am trying to create a login id and password form in Access 2007. I got this code from a site, however when implemented, it is constantly showing an error "Invalid Password. Please try again" even when passwords are correct. I have tried almost every possible thing. Also the last part of three failed attempts is not working. Kindly check the code below and please help with the possible error. Any information would be of great help.

    Code:
    Private Sub Combo2_AfterUpdate()
       Me.Text2.SetFocus
    End Sub
    Private Sub Command6_Click()
    'Check to see if data is entered into the UserName combo box
       If IsNull(Me.Combo2) Or Me.Combo2 = "" Then
          MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
          Me.Combo2.SetFocus
          Exit Sub
       End If
       'Check to see if data is entered into the password box
       If IsNull(Me.Text2) Or Me.Text2 = "" Then
          MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
          Me.Text2.SetFocus
          Exit Sub
       End If
       'Check value of password in tblEmployees to see if this
       'matches value chosen in combo box
       If Me.Text2.Value = DLookup("strEmpPassword", "tblEmployees", _
                                   "[lngEmpID]=" & Me.Combo2.Value) Then
          DoCmd.Close acForm, [frmlogon], acSaveNo
          DoCmd.OpenForm "frmSplash_Screen"
       Else
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                 "Invalid Entry!"
          Me.Text2.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
    Thanks in Advance
    Aman
    Last edited by RuralGuy; 07-06-2011 at 11:44 AM. Reason: Addes code tags

  2. #2
    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
    Where is the variable intLogonAttempts defined? I would single step your code and see what values are being used by the DLookup().

  3. #3
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43
    Hi,

    Thanks for your reply

    I am very much new to Access Coding. As per my understanding, I have not defined the variable intdatabaselogon as you have mentioned. Please guide me further on the process to solve this issue.

    Aman

  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
    Start by making sure these two lines are at the top of your code (class) module for the form:
    Option Compare Database
    Option Explicit
    ...then define the variable *before* any procedures:
    Dim intLogonAttempts as Integer
    ...which makes it available to all of the procedures within this module.

  5. #5
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43
    Hi,

    Just did what you mentioned. Still I am facing the same problem, its not closing after three failed attempts.

    Aman

  6. #6
    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
    Do you know how to single step the code? Click to the left of the margin in the editor and it will put a breakpoint on that line. then F8 one line at a time. If you hover over a variable, a pop-up will show you what it contains.

  7. #7
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43
    Hi,

    I tried doing that, when I clicked on the last part (Which is not working) and used F8, below mentioned lines also got marked in red. However there was no popup.

    If Me.Text2.Value = DLookup("strEmpPassword", "tblEmployees", _
    "[lngEmpID]=" & Me.Combo2.Value) Then
    lngMyEmpID = Me.Combo2.Value

    Aman

  8. #8
    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
    Does you code compile without errors? Debug>Compile

  9. #9
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43
    No, it does not give any error. It merely not performs the last part of the code. I have a question, can it because of the "Data Type" I have defined for Password field in my table. I have fixed it to "Text". When I used "Number", it kept on showing "Invalid Password" message box.

    Once I changed it to Text, it allowed Password Matching with Login Name. But it is not performing the last part where after 3 failed attempts the form closes automatically.

  10. #10
    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
    Can you do a Compact and Repair and Zip up your db and post it?

  11. #11
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43
    Hi,

    Please find attached the database as required.
    Thanks a lot for replying.

    Aman

  12. #12
    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
    The top of your module should have looked like this:
    Code:
    Option Compare Database
    Option Explicit
    Dim intDatabaseLogonAttempts As Integer
    Private Sub Combo2_AfterUpdate()
       Me.Text2.SetFocus
    End Sub
    Instead, you defined the variable within the procedure.

  13. #13
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43
    Hi,

    Thanks a lot. Its working now. Can you please help me in understanding the objective behind defining this variable and why it needs to be placed on the top of the code.

    Secondly, currently I am only able to enter Number in the password column of the table. Whenever I insert alphabets, the error message of Invalid Password starts coming. Is there any way I can add alphabets or symbols to the password.

    Once again thanks for your patience.

    Aman

  14. #14
    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
    Your intDatabaseLogonAttempts variable needs to be a global variable the way you have it coded. When you put it within a procedure then it is scoped to that procedure only and reset to 0 everytime you enter that procedure. As for your password issue, I have no problem. I can enter and use both numbers and alpha characters.

  15. #15
    amangupts is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    43
    Thanks a lot. Its working absolutely fine now.
    Kindly bear with me. Is there any way to record the number of attempts made by any person in database by inserting a column in the main table or otherwise as well.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Login Form Code
    By paddon in forum Programming
    Replies: 4
    Last Post: 04-08-2011, 06:48 PM
  2. Replies: 1
    Last Post: 12-02-2010, 11:08 PM
  3. VB Code in Access 2007
    By collen in forum Programming
    Replies: 1
    Last Post: 10-12-2010, 06:27 AM
  4. Login/Password Code not working
    By eww in forum Programming
    Replies: 3
    Last Post: 09-21-2010, 10:49 AM
  5. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM

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