ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA - Close Event for Password Userform (https://www.excelbanter.com/excel-programming/429942-re-excel-vba-close-event-password-userform.html)

Peter T

Excel VBA - Close Event for Password Userform
 
Here's one way to do it but I strongly suggest you don't use this!
What happens if poor user has forgotten the password...

''' add TextBox1 to the form and type "abc" into it

Private mbPWOK As Boolean
Private Const mcPW As String = "abc"

Private Sub TextBox1_AfterUpdate()
ValidatePW
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If mbPWOK = False Then ValidatePW
If mbPWOK = False Then
Cancel = True
MsgBox "won't close with invalid password"
End If
End Sub

Function ValidatePW() As Boolean

mbPWOK = LCase(TextBox1.Text) = LCase(mcPW)
ValidatePW = mbPWOK

End Function





"Marcolino" wrote in message
...
Is there a way to program a close event for a password userform, so that
if
the user tries to close the form before entering a password, it generates
an
error message and reloads the form?





All times are GMT +1. The time now is 03:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com