Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do-Loop Question

Status
Not open for further replies.

Bill6868

Technical User
Mar 20, 2007
96
US
I have never quite understood the Do-Loop function. I have a database that opens with a splash screen that asks for a password. How can I get the application to shut down after say, 3 or 4 our unsuccessful attempts?

Any guidence would be most appreciated.

Thanks,

Bill
 

Create a variable that you increment each time the attempt is made. Once the value reaches a set limit, quit the application.
Something like this...
Code:
If txtPassword <> Password Then
   intAttempts = intAttempts + 1
   If intAttempts > 3 Then
      DoCmd.Quit
   End If
End If


Randy
 
Also note that the variable intAttempts has to be declared as Static in order for it to keep its value between attempts:
Code:
Static intAttempts

If txtPassword <> Password Then
   intAttempts = intAttempts + 1
   If intAttempts > 3 Then
      DoCmd.Quit
   End If
End If

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thank you Randy and Missingliong. Much appreciated!
 
Thanks to all. Here is a solution I worked out in a test database:

Private Sub Command1_Click()

Static intAttempts

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If [Password] = "familysupport" Then
DoCmd.OpenForm "frmMainMenu"
End If

If [Password] <> "familysupport" Then
MsgBox "incorrect password, please try again"
intAttempts = intAttempts + 1
If intAttempts > 2 Then
DoCmd.Quit
End If
End If

End Sub
 
Code:
Private Sub Command1_Click()

    Static intAttempts
    
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    If [Password] = "familysupport" Then
        DoCmd.OpenForm "frmMainMenu"
    [s]End If[/s]
    [b][COLOR=red]Else[/color][/b]
    [s]If [Password] <> "familysupport" Then[/s]
        MsgBox "incorrect password, please try again"
        intAttempts = intAttempts + 1
        If intAttempts > 2 Then
            DoCmd.Quit
        End If
    End If
    
End Sub

You should consider storing the password in a table so you don't have to edit your code every time it changes.


Randy
 
Thanks Randy. The password is stored in a table, which holds just one record. In the form's (splash screen pop-up) on open event, the DoCmd runs a delete query then opens up the form to to a new record. After the user types in the password they click an OK button. This saves the record and then runs the password procedure.

I know some of the things I do in Access could probably be done in an easier way - I'm just a technical user, but I do most of the times find a way to get my applications to do what I need it to do, especially with the help I get from Tek-Tips.

This password procedure works, but from a programmer's point of view, is this a valid approach/solution? Is there a better way?

Thanks to everyone for your help, I can use this intAttempts concept in many other ways.

Bill

 
One final comment about the aforementioned password procedure: It seems the easiest and most secure password procedure can accomplished by using the “Encrypt with Password” wizard from the Database Tools tab. This works really well, however, if I were to pass the database over to a group of users, and at some point down the road they forgot the password, there is no recourse (that I know of) of opening the database. You can’t even import the objects into a new database to start over again without providing the password. You couldn’t even link a table to another database without having to provide the password.

The objective of the aforementioned procedure is to establish a “nuisance or deterrence” to prevent an unauthorized casual user from “snooping” around in the database; a “dime store” lock, so to speak – something a programmer would easily be able to fix if the group forgot the password. Sort of like the lock on Al Gore’s Social Security “lockbox” proposal – easily breached.

I dunno – any comments would be appreciated.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top