I'm an Access newbie, and would like to make a password entry/validation private subroutine into a re-usable library function but am unsure of the best way to do it.
I have two buttons on a menu form.
btnMaintenance (default state: visible,disabled)
btnEnableMaintenance (default state: visible, enabled)
When the user clicks on btnEnableMaintenance, a form is opened and the user is prompted to enter a password.
If the password is valid, then btnMaintenance is enabled.
After three failed attempts, the password entry form window will close and btnMaintenance remains disabled.
At the moment, the name of the controls and valid password are hardcoded into Password_AfterUpdate()
Ideally, I'd use the new password function with three parameters, like this:
EnableButton(ButtonNameToEnable,ButtonEnable,Password)
where:
1) ButtonNameToEnable is the name of the button to enable (initial state is disabled)
2) ButtonEnable is the name of the button which has to be clicked on to enable ButtonNameToEnable
3) Password is the valid password required to enable ButtonNameToEnable
Any suggestions or constructive criticism gratefully welcomed!
Thanks!
DMTelf
<code>
Option Explicit
Dim gOkToClose As Boolean
Dim gintNumberOfPasswordAttempts As Integer
Private Sub Form_Load()
gOkToClose = False
' number of tries
gintNumberOfPasswordAttempts = 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not gOkToClose Then
Cancel = True
End If
End Sub
Private Sub Password_AfterUpdate()
' txtPassword is the name of the text control where the password is input by the user.
If Me![txtPassword] = "p" Then
gOkToClose = True
Forms!frmMenu!btnMaintenance.Enabled = True
Forms!frmMenu!btnMaintenance.SetFocus
Forms!frmMenu!btnEnableMaintenance.Enabled = False
DoCmd.Close A_FORM, "frmPassword"
Else
' give them three shots at getting it right
Select Case gintNumberOfPasswordAttempts
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintNumberOfPasswordAttempts = gintNumberOfPasswordAttempts + 1
Case Else
DoCmd.Beep
gOkToClose = True
DoCmd.Close A_FORM, "frmPassword"
End Select
End If
End Sub
</code>
I have two buttons on a menu form.
btnMaintenance (default state: visible,disabled)
btnEnableMaintenance (default state: visible, enabled)
When the user clicks on btnEnableMaintenance, a form is opened and the user is prompted to enter a password.
If the password is valid, then btnMaintenance is enabled.
After three failed attempts, the password entry form window will close and btnMaintenance remains disabled.
At the moment, the name of the controls and valid password are hardcoded into Password_AfterUpdate()
Ideally, I'd use the new password function with three parameters, like this:
EnableButton(ButtonNameToEnable,ButtonEnable,Password)
where:
1) ButtonNameToEnable is the name of the button to enable (initial state is disabled)
2) ButtonEnable is the name of the button which has to be clicked on to enable ButtonNameToEnable
3) Password is the valid password required to enable ButtonNameToEnable
Any suggestions or constructive criticism gratefully welcomed!
Thanks!
DMTelf
<code>
Option Explicit
Dim gOkToClose As Boolean
Dim gintNumberOfPasswordAttempts As Integer
Private Sub Form_Load()
gOkToClose = False
' number of tries
gintNumberOfPasswordAttempts = 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not gOkToClose Then
Cancel = True
End If
End Sub
Private Sub Password_AfterUpdate()
' txtPassword is the name of the text control where the password is input by the user.
If Me![txtPassword] = "p" Then
gOkToClose = True
Forms!frmMenu!btnMaintenance.Enabled = True
Forms!frmMenu!btnMaintenance.SetFocus
Forms!frmMenu!btnEnableMaintenance.Enabled = False
DoCmd.Close A_FORM, "frmPassword"
Else
' give them three shots at getting it right
Select Case gintNumberOfPasswordAttempts
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintNumberOfPasswordAttempts = gintNumberOfPasswordAttempts + 1
Case Else
DoCmd.Beep
gOkToClose = True
DoCmd.Close A_FORM, "frmPassword"
End Select
End If
End Sub
</code>