Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75

    Code Correction :|

    If Me.PASS.Value = Nz(DLookup("Password", "tblEmployees", "[Employee]=" & Chr(34) & Me.EMP.Value & Chr(34)), vbNullString) Then
    gstrUserName = Me.EMP.Value
    gstrPassword = Me.PASS.Value

    'Close logon form and open splash screen

    DoCmd.Close acForm, "UserNew", acSaveNo
    DoCmd.OpenForm "Data"

    Else
    Countabc = Countabc + 1
    If Countabc > 3 Then
    MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
    Application.Quit
    Else

    MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
    Me.PASS.SetFocus
    End If
    End If
    Me.EMP.SetFocus





    I actually wanna close the appilcation if the passwrod is incorrect for 3 times....
    Please advise if the above code is incorrect....

  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,917
    Where is this code located? In what event?

  3. #3
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75
    In user and password form
    under the login button....

  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,917
    Where have you defined the Countabc variable?

  5. #5
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75
    I dint get you with Countabc.....

  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,917
    Countabc = Countabc + 1
    If Countabc > 3 Then
    ...where did you Dim this variable?

  7. #7
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75
    In the starting of the same Function..,


    here is the code...


    Private Sub Command4_Click()
    Dim Count As String
    Countabc = 0
    'Check to see if data is entered into the UserName combo box
    Me.EMP.SetFocus
    If IsNull(Me.EMP) Or Me.EMP = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.EMP.SetFocus
    Exit Sub
    End If
    'Check to see if data is entered into the password box
    If IsNull(Me.PASS) Or Me.PASS = "" Then
    MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
    Me.PASS.SetFocus
    Exit Sub
    End If
    'Check value of password in tblEmployees to see if this matches value chosen in combo box
    If Me.PASS.Value = Nz(DLookup("Password", "tblEmployees", "[Employee]=" & Chr(34) & Me.EMP.Value & Chr(34)), vbNullString) Then
    gstrUserName = Me.EMP.Value
    gstrPassword = Me.PASS.Value

    'Close logon form and open splash screen

    DoCmd.Close acForm, "UserNew", acSaveNo
    DoCmd.OpenForm "Data"
    Else
    Countabc = Countabc + 1
    If Countabc > 3 Then
    MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
    Application.Quit
    Else

    MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
    Me.PASS.SetFocus
    End If
    End If

    'If User Enters incorrect password 3 times database will shutdown


    End Sub

  8. #8
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75
    I corrected the Dim Count As String to Dim Countabc As String...
    But still it doesnot work

  9. #9
    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,917
    You need to define this variable *outside* of any procedure:
    Option Compare Database
    Option Explicit
    Dim Countabc As Integer
    Private Sub Command4_Click()
    ...
    Notice I defined it as an Integer rather than a String. The way you have it defined (inside the procedure) it startes at zero *every* time the button is pressed.

  10. #10
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75
    Still, the application keeps asking for the password

    It should close after the third attempt

  11. #11
    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,917
    Maybe you should post your zipped up db so we can look at it. Either that or post all of the code on the code module for the form from top to bottom.

  12. #12
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    Option Compare Database
    Option Explicit
    Dim Countabc As Integer

    Private Sub Command4_Click()
    Dim Countabc as String
    Countabc = 0
    .
    .
    .
    Remove the last two statements from the code segment shown above, if they are still there, and retry.

  13. #13
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75
    HI,

    Which statements :S

  14. #14
    hitesh_asrani_j is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    75
    ITs working

  15. #15
    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,917
    Thanks for posting back with your success.

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

Similar Threads

  1. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  2. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  3. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  4. Help with VBA Code
    By access.newby in forum Forms
    Replies: 1
    Last Post: 11-15-2009, 05:43 AM
  5. Need help with code
    By hoenheim in forum Programming
    Replies: 9
    Last Post: 09-11-2008, 04:19 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