Password Protecting a Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • student2
    New Member
    • Aug 2009
    • 36

    Password Protecting a Form

    Hi.
    I've placed the following code on the click event of a command button that leads to a form that is password protected:-

    Code:
    Private Sub cmdSales_Click()
      Dim strPasswd
      strPasswd = InputBox("Enter Password", "Restricted Form") 
      If strPasswd = "" Or strPasswd = Empty Then
      MsgBox "This Field cannot be left blank", vbInformation, "Required Data"
      Exit Sub
      End If
       
       If strPasswd = "HELP" Then
       DoCmd.OpenForm "SalesSub", acNormal
       End If
       Exit Sub
       End Sub
    However, I want to be able to also show :-
    1) a message box if the password entered is False/Incorrect ( I've tried "If strPasswd=False ) but this I realize is incorrect.

    and

    2) Instead of having my actual password shown as "HELP" in the prompt box that is displayed, I'd prefer to have it shown as "****".

    Any assistance would be greatly appreciated.
    Thanks again!
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    For 1) use
    Code:
    If strPasswd = "HELP" Then
       ...
    Else
       MsgBox "Bad Password!"
    End If
    2) The InputBox function is nice, but it doesn't support this. If you want to make your own form with a text box, you can set an input mask with *s.

    Comment

    • student2
      New Member
      • Aug 2009
      • 36

      #3
      Ok, thanks a mil again.
      Will try them both.

      Thank you very much.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        I personally feel that Passwords should be case sensitive, in which case:
        Code:
        If StrComp(strPasswd, "HELP", vbBinaryCompare) = 0 Then
           '...
        Else
           MsgBox "Bad Password!"
        End If
        P.S. = Help, HeLP, HELp, heLp, help, etc. will NOT pass the test, and result in the Message Box being displayed.

        Comment

        • student2
          New Member
          • Aug 2009
          • 36

          #5
          Oh Ah! :-)
          Thanks to you both!

          tyvm

          Comment

          Working...