adding an attempt onto my password

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sakar11111
    New Member
    • Apr 2017
    • 1

    adding an attempt onto my password

    hi guys,
    i want to add attempt onto my password so that the person login in only has a limited amount of attempt they can try to enter the corret password but I have no idea how to do it can someone guide me on how to do it.
    this code works fine if the person makes a mistake. (It does not let the person log in but it does not give the person another chance.)

    Code:
     
    Private Sub Form_Open(Cancel As Integer)
    
    Dim password As String
    
    password = InputBox("Please enter the correct password.")
    
    If password = "Rodney" Then
    MsgBox "Welcome to the Booking System on Nottingham Academy"
    
    Else
    
    MsgBox "Incorrect. Please try again"
    
    DoCmd.Close
    DoCmd.Close acForm, "HomePage"
    
    End If
    
    End Sub
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    You have a couple of solutions, but the best solutions are either a Do..While loop or a Do..Until loop. Below are examples of how you would use them.

    Do..Until
    Code:
    Private Sub Form_Open(Cancel As Integer)
    	Dim countLoginTries As Integer = 0
    	Dim totalLoginTries As Integer = 3
    
    	Do
    		Dim password As String
    		
    		password = InputBox("Please enter the correct password."
    		
    		If password = "Rodney" Then
    			MsgBox "Welcome to the Booking System on Nottingham Academy"
    		Else
    			MsgBox "Incorrect.  Please try again."
    			DoCmd.Close
    			DoCmd.Close acForm, "HomePage"
    		End If
    		
    	Loop Until countLoginTries > totalLoginTries
    End Sub
    Do..While
    Code:
    Private Sub Form_Open(Cancel As Integer)
    	Dim countLoginTries As Integer = 0
    	Dim totalLoginTries As Integer = 3
    
    	Do While countLoginTries <= totalLoginTries
    		Dim password As String
    		
    		password = InputBox("Please enter the correct password."
    		
    		If password = "Rodney" Then
    			MsgBox "Welcome to the Booking System on Nottingham Academy"
    		Else
    			MsgBox "Incorrect.  Please try again."
    			DoCmd.Close
    			DoCmd.Close acForm, "HomePage"
    		End If
    		
    	Loop
    End Sub

    Comment

    Working...