By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Password Form

Slaxer13
100+
P: 106
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
Jun 27 '14 #1

✓ answered by twinnyfo

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:

Expand|Select|Wrap|Line Numbers
  1. Public Sub DeleteTheRecord()
  2.     DoCmd.RunCommand acCmdDeleteRecord
  3. End Sub
Then, in your Password Form, once the Password is validated, call the function:

Expand|Select|Wrap|Line Numbers
  1. 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.

Share this Question
Share on Google+
14 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,482
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:

Expand|Select|Wrap|Line Numbers
  1. Public Sub DeleteTheRecord()
  2.     DoCmd.RunCommand acCmdDeleteRecord
  3. End Sub
Then, in your Password Form, once the Password is validated, call the function:

Expand|Select|Wrap|Line Numbers
  1. 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.
Jun 28 '14 #2

NeoPa
Expert Mod 15k+
P: 31,768
That's a perfect answer. However - consider an alternative approach which should make your job easier.
  1. In your cmdDelete code have something like :
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cmdDelete_Click()
    2.     If Not ValidatePassword() Then Exit Sub
    3.     'Code to do whatever deletion you want here.
    4. End Sub
  2. Your ValidatePassword() 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_AfterUpdate() event handler so that the code that opens frmPassword knows it can proceed :
    Expand|Select|Wrap|Line Numbers
    1. Private Sub txtPassword_AfterUpdate()
    2.     Me.chkDone = True
    3. End Sub
  4. Expand|Select|Wrap|Line Numbers
    1. Public Function ValidatePassword() As Boolean
    2.     Dim frmPW As Form_frmPassword
    3.  
    4.     Call DoCmd.OpenForm("frmPassword")
    5.     With Forms("frmPassword")
    6.         Do Until .chkDone
    7.             DoEvents
    8.         Loop
    9.         ValidatePassword = (.txtPassword = .txtCOD)
    10.         Call .Close(ObjectType:=acForm _
    11.                   , ObjectName:="frmPassword"
    12.                   , Save:=acSaveNo)
    13.     End With
    14. End Function
NB. The code here is all air-code so may need fixing in places, but should illustrate the idea at least.
Jun 28 '14 #3

burrina
P: 6
Easy Way! Using OnOpenEvent. Of course, you can change the Msg and Password to your liking.

Expand|Select|Wrap|Line Numbers
  1. Cancel = (InputBox("Please Enter a Password ?") <> "authorized")
HTH
Jun 29 '14 #4

NeoPa
Expert Mod 15k+
P: 31,768
I'm not sure you quite understand the question. Certainly that doesn't represent a solution I'm afraid.
Jun 30 '14 #5

burrina
P: 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.
Expand|Select|Wrap|Line Numbers
  1.  
  2. If IsNull(Forms!frmPassword!Text0) Then               'No Blank passwords allowed
  3.     MsgBox "You cannot enter a blank Password. Try again."
  4.     Me!Text0.SetFocus
  5. Else
  6.     'No More Than 3 Attempts Allowed
  7.     If Me.LIChk > 2 Then
  8.         MsgBox "Only three Password entry attempts allowed.", vbCritical + vbOKOnly, "Oops!"
  9.             DoCmd.quit
  10.  
  11.         ElseIf Forms!frmPassword!Text0 = "password" Then    'Change To Your Password.
  12.             DoCmd.SetWarnings False
  13.            If MsgBox("Do you wish to delete this record?", vbYesNo, "Delete Confirmation") = vbYes Then
  14.    If MsgBox("Are you SURE you want to delete this record?" & vbCrLf & _
  15.     "This will permanently delete the record.", vbYesNo, "2nd Delete Confirmation") = vbYes Then
  16.     DoCmd.SelectObject acForm, "frmOne" 'Change To Your Form Name.
  17.          DoCmd.RunCommand acCmdDeleteRecord
  18.          DoCmd.SetWarnings True
  19.          DoCmd.Close acForm, Me.Name
  20.  
  21.  
  22.         End If
  23.             End If
  24.                 End If
  25.                     End If
EDITED: Sorry for not understanding the 1st time.
Jun 30 '14 #6

Slaxer13
100+
P: 106
Good morning ppl. How are you?
NeoPa the validatepassword() 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
Jun 30 '14 #7

Slaxer13
100+
P: 106
twinnyfo:
Expand|Select|Wrap|Line Numbers
  1. Forms!FormName.DeleteTheRecord
It says the "command or action "deleterecord" is not available at the moment"

NeoPa:
Expand|Select|Wrap|Line Numbers
  1. Call .Close(ObjectType:=acForm _
  2.                        , ObjectName:="frmPassword" _
  3.                        , Save:=acSaveNo)
it says "application-defined or object-defined error"
Jun 30 '14 #8

Slaxer13
100+
P: 106
twinnyfo: it was not:
Expand|Select|Wrap|Line Numbers
  1. 1.Forms!FormName.DeleteTheRecord
i used:
Expand|Select|Wrap|Line Numbers
  1. Form_frmUtente.DeleteTheRecord
Jun 30 '14 #9

NeoPa
Expert Mod 15k+
P: 31,768
Slaxer:
NeoPa the validatepassword() 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.
Slaxer:
it says "application-defined or object-defined error"
Apologies. It was air-code and this bit I got wrong. It should say :
Expand|Select|Wrap|Line Numbers
  1.         Call DoCmd.Close(ObjectType:=acForm _
  2.                        , ObjectName:="frmPassword"
  3.                        , Save:=acSaveNo)
Jun 30 '14 #10

Slaxer13
100+
P: 106
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
Jun 30 '14 #11

Slaxer13
100+
P: 106
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
Jun 30 '14 #12

NeoPa
Expert Mod 15k+
P: 31,768
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!
Jun 30 '14 #13

Slaxer13
100+
P: 106
Thanks NeoPa. I just am what people are to me ;)
Jul 1 '14 #14

NeoPa
Expert Mod 15k+
P: 31,768
I'll try to avoid being rude to you then :-D

PS. I understand you really. Just having a joke :-)
Jul 1 '14 #15

Post your reply

Sign in to post your reply or Sign up for a free account.