Password Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Slaxer13
    New Member
    • Jun 2014
    • 106

    Password Form

    Hi ppl.
    I did a form called frmPassword. It opens when someone clicks the delete button. That form has two textoboxes and two buttons. txtCod which is invisible and where the password is stored. txtPassword where the user enters the password. btnOk button to confirm the password. btnCancel to cancel and return to the previous form without deleting anything.

    The question is: what is the code that i must use on the btnOk? I want it to check if the txtPassword has the same value as in the txtCod. If they are the same it triggers the delete button onclick event. if they are not the same i want it to display a msgbox sayng "error, wrong pass". the msgbox i know how to do but i don't know how to trigger the delete button...

    Help appreciated, Slaxer13
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    slaxer,

    Remember, your delete button triggers the password authentication. That is the key. Create another Public Function or Sub in the Main form which actually deletes the record. Could be as simple as:

    Code:
    Public Sub DeleteTheRecord()
        DoCmd.RunCommand acCmdDeleteRecord
    End Sub
    Then, in your Password Form, once the Password is validated, call the function:

    Code:
    Forms!FormName.DeleteTheRecord
    Trying to remember off the top of my head if I nee to add "Form." before the delete. But one or the other should work.

    Just make sure the Function/Sub is Public, otherwise it won't work.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      That's a perfect answer. However - consider an alternative approach which should make your job easier.
      1. In your cmdDelete code have something like :
        Code:
        Private Sub cmdDelete_Click()
            If Not ValidatePassword() Then Exit Sub
            'Code to do whatever deletion you want here.
        End Sub
      2. Your ValidatePasswor d() procedure would be a Public function defined in a standard module. It would incorporate the checking logic you already have then return a Boolean value of True if the test was passed and False if it weren't.
      3. Your frmPassword form should be set up with a hidden CheckBox which defaults to False but is set to True by the txtPassword_Aft erUpdate() event handler so that the code that opens frmPassword knows it can proceed :
        Code:
        Private Sub txtPassword_AfterUpdate()
            Me.chkDone = True
        End Sub
      4. Code:
        Public Function ValidatePassword() As Boolean
            Dim frmPW As Form_frmPassword
        
            Call DoCmd.OpenForm("frmPassword")
            With Forms("frmPassword")
                Do Until .chkDone
                    DoEvents
                Loop
                ValidatePassword = (.txtPassword = .txtCOD)
                Call .Close(ObjectType:=acForm _
                          , ObjectName:="frmPassword"
                          , Save:=acSaveNo)
            End With
        End Function

      NB. The code here is all air-code so may need fixing in places, but should illustrate the idea at least.

      Comment

      • burrina
        New Member
        • Jun 2014
        • 6

        #4
        Easy Way! Using OnOpenEvent. Of course, you can change the Msg and Password to your liking.

        Code:
        Cancel = (InputBox("Please Enter a Password ?") <> "authorized")
        HTH

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          I'm not sure you quite understand the question. Certainly that doesn't represent a solution I'm afraid.

          Comment

          • burrina
            New Member
            • Jun 2014
            • 6

            #6
            This is not my thread. However, after looking back at it, yes that is true. I would have a command button that opens another password form that asks for confirmation.
            Code:
            If IsNull(Forms!frmPassword!Text0) Then               'No Blank passwords allowed
                MsgBox "You cannot enter a blank Password. Try again."
                Me!Text0.SetFocus
            Else
                'No More Than 3 Attempts Allowed
                If Me.LIChk > 2 Then
                    MsgBox "Only three Password entry attempts allowed.", vbCritical + vbOKOnly, "Oops!"
                        DoCmd.quit
                    
                    ElseIf Forms!frmPassword!Text0 = "password" Then    'Change To Your Password.
                        DoCmd.SetWarnings False
                       If MsgBox("Do you wish to delete this record?", vbYesNo, "Delete Confirmation") = vbYes Then
               If MsgBox("Are you SURE you want to delete this record?" & vbCrLf & _
                "This will permanently delete the record.", vbYesNo, "2nd Delete Confirmation") = vbYes Then
                DoCmd.SelectObject acForm, "frmOne" 'Change To Your Form Name.
                     DoCmd.RunCommand acCmdDeleteRecord
                     DoCmd.SetWarnings True
                     DoCmd.Close acForm, Me.Name
              
                        
                    End If
                        End If
                            End If
                                End If
            EDITED: Sorry for not understanding the 1st time.

            Comment

            • Slaxer13
              New Member
              • Jun 2014
              • 106

              #7
              Good morning ppl. How are you?
              NeoPa the validatepasswor d() function where should i put it? frmPassword or on the form where the delete button is?

              Thanks for all the help (NeoPa and the others) ;)
              Cheers, Slaxer13
              Last edited by Slaxer13; Jun 30 '14, 08:59 AM. Reason: Better formed question

              Comment

              • Slaxer13
                New Member
                • Jun 2014
                • 106

                #8
                twinnyfo:
                Code:
                Forms!FormName.DeleteTheRecord
                It says the "command or action "deletereco rd" is not available at the moment"

                NeoPa:
                Code:
                Call .Close(ObjectType:=acForm _
                                       , ObjectName:="frmPassword" _
                                       , Save:=acSaveNo)
                it says "applicatio n-defined or object-defined error"

                Comment

                • Slaxer13
                  New Member
                  • Jun 2014
                  • 106

                  #9
                  twinnyfo: it was not:
                  Code:
                  1.Forms!FormName.DeleteTheRecord
                  i used:
                  Code:
                  Form_frmUtente.DeleteTheRecord

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Originally posted by Slaxer
                    Slaxer:
                    NeoPa the validatepasswor d() function where should i put it? frmPassword or on the form where the delete button is?
                    That depends. If you want it to be available universally then put it in its own separate module (or at least somewhere in a Standard module). If it's only ever going to be used from your first (calling) form then it can go in that form's module.
                    Originally posted by Slaxer
                    Slaxer:
                    it says "applicatio n-defined or object-defined error"
                    Apologies. It was air-code and this bit I got wrong. It should say :
                    Code:
                            Call DoCmd.Close(ObjectType:=acForm _
                                           , ObjectName:="frmPassword"
                                           , Save:=acSaveNo)
                    Last edited by NeoPa; Jun 30 '14, 10:19 AM.

                    Comment

                    • Slaxer13
                      New Member
                      • Jun 2014
                      • 106

                      #11
                      Thanks NeoPa. I managed to put twinnyfo's idea to work while I was waiting for your response. His idea works fine but I'll try yours and see which fits best ;)

                      Cheers, Slaxer13
                      Last edited by NeoPa; Jun 30 '14, 04:24 PM. Reason: Spelling of "idea"

                      Comment

                      • Slaxer13
                        New Member
                        • Jun 2014
                        • 106

                        #12
                        I managed to put the two ideas to work but, from my point of view, seems that twinnyfo's idea is more simple although they are both correct. I will mark twinnyfo's idea since I used it but for searches this thread know that both ideas are perfectly usable. As for burrina's answer I have not tried it as for me I find it a bit confusing (i am a beginner so the simpler the better and since there are one or two commands I am not familiarized with...), but I am not saying is wrong ;)

                        Cheers, Slaxer13
                        Last edited by NeoPa; Jun 30 '14, 04:25 PM. Reason: Spelling of "idea"

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32633

                          #13
                          It's a pleasure working with someone who is polite to all and takes the time to explain where they're at.

                          Welcome to Bytes!

                          Comment

                          • Slaxer13
                            New Member
                            • Jun 2014
                            • 106

                            #14
                            Thanks NeoPa. I just am what people are to me ;)

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32633

                              #15
                              I'll try to avoid being rude to you then :-D

                              PS. I understand you really. Just having a joke :-)

                              Comment

                              Working...