Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2014
    Posts
    4

    Unanswered: Password protecting a form

    I tried using the code from the code bank to password protect a form. However when I type in the wrong password it still lets me into the form.

    This is the code I'm using

    Private Sub Form_Open(Cancel As Integer)



    Dim user As String
    Dim pwd As String
    user = InputBox("username")
    pwd = InputBox("Password")
    If pwd = "password" And user = "user" Then
    MsgBox "Access Granted"
    Else
    MsgBox "Incorrect Login"
    DoCmd.Close
    End If

    End Sub

    I need it to close the form if the password or user name is wrong

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    Else
        MsgBox "Incorrect Login"
        Cancel = True
    End If
    Have a nice day!

  3. #3
    Join Date
    Sep 2014
    Posts
    4
    Thanks that worked perfectly

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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