Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005

    Unanswered: PW Protecting a Form

    I have a form that is password protected by using a table in Access that stores the password. The form uses the following code on the OnOpen event. Everything works fine up to the point where a user enters the wrong password (I’ve highlighted the section below) The Message “Sorry you entered the wrong password” & “Incorrect Password” pops up, but when you click on either the vbOKOnly button, or the little red X on the password form, it closes out the entire database file, not just the password form. I tried taking out db.Close but the same result occurs.

    How can I get just the “frmPassword” and the protected form to close/fail to open, instead of the whole database file? Or how could I code to shut down MS Access on a fail?

    Private Sub Form_Open(Cancel As Integer)

    Dim Hold As Variant

    Dim tmpKey As Long

    Dim I As Integer

    Dim rs As DAO.Recordset

    Dim db As DAO.Database

    On Error GoTo Error_Handler

    ' Prompt the user for the Password.

    DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog

    Hold = MyPassword

    ' Open the table that contains the password.

    Set db = CurrentDb

    Set rs = db.OpenRecordset("tblPassword", dbOpenTable)

    rs.Index = "PrimaryKey"

    rs.Seek "=",

    If rs.NoMatch Then

    MsgBox "Sorry cannot find password information. Try Again"

    Cancel = -1


    ' Test to see if the key generated matches the key in

    ' the table; if there is not a match, stop the form

    ' from opening.

    If Not (rs![KeyCode] = KeyCode(CStr(Hold))) Then

    MsgBox "Sorry you entered the wrong password." & _

    "Try again.", vbOKOnly, "Incorrect Password"

    Cancel = -1

    End If

    End If



    Exit Sub


    MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number

    Exit Sub

    End Sub

  2. #2
    Join Date
    Feb 2004
    One Flump in One Place

    Have you tried setting a breakpoint and stepping through the code? If you can work out how to do this you will probably come across the answer. Check out help. My suspicion is you have something like an DoCmd.Quit on the close or unload event of the form.

    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Dec 2004
    Madison, WI


    Here's a little different approach but maybe you can use something from the attachment.
    Attached Files Attached Files
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts