Results 1 to 6 of 6
  1. #1
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153

    Creating a password protected FORM

    So I got this code somewhere on the web:


    Dim pwd As String
    pwd = InputBox("What is the Password?")
    If pwd = "TC" Then
    MsgBox "You're In"
    Else
    MsgBox "Nice Try Wise Guy, You're Out!!"
    DoCmd.Close


    End If



    What its suppose to is have the form password protected so that you have to enter the correct password to access it. However when I use it EVEN if you type in the WRONG password, it still allows you to access the form. What is wrong with this coding

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,684
    What event is this code in?

    Name the object to be closed:

    DoCmd.Close acForm, Me.Name, acSaveNo
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Quote Originally Posted by June7 View Post
    What event is this code in?

    Name the object to be closed:

    DoCmd.Close acForm, Me.Name, acSaveNo
    Its in the On Open Event. If my form is named SEARCH how should I rename the code?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,684
    Don't need the DoCmd line. Open event has a Cancel argument.

    Private Sub Form_Open(Cancel As Integer)
    If InputBox("What is the Password?") <> "TC" Then
    MsgBox "Nice Try Wise Guy, You're Out!!"
    Cancel = True
    End If
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Wow! Not only is the Code you provided shorter, but it works great!!! Huge help!! Thanks a Million!!!

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,684
    Oh, to answer your other question, the DoCmd line would not have to be modified in any way unless you want code in one form to close another form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Password protected form or report
    By mar_t in forum Access
    Replies: 11
    Last Post: 06-20-2013, 05:52 AM
  2. Replies: 2
    Last Post: 09-21-2012, 05:12 PM
  3. Open a password protected MDB/MDW
    By abcc14 in forum Security
    Replies: 8
    Last Post: 11-02-2011, 07:41 AM
  4. Replies: 4
    Last Post: 09-14-2011, 12:33 AM
  5. Password protected Switcboard buttons
    By mar_t in forum Access
    Replies: 9
    Last Post: 07-23-2011, 08:13 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
  •  
Tech Forums: Microsoft Office Forums