Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel VBA - Close Event for Password Userform

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel VBA - Close Event for Password Userform

Would this also prevent a user from simply clicking on the X in the top-right
corner of the userform, which simply ends the subroutine?

I can't seem to add a control to that X to prevent this from happening.

Thanks

"Peter T" wrote:

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?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Excel VBA - Close Event for Password Userform

Yes, all you had to do was simply try it

Regards,
Peter T

"Marcolino" wrote in message
...
Would this also prevent a user from simply clicking on the X in the
top-right
corner of the userform, which simply ends the subroutine?

I can't seem to add a control to that X to prevent this from happening.

Thanks

"Peter T" wrote:

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?






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel VBA - Close Event for Password Userform

Ok, I'll try it, thanks.


"Peter T" wrote:

Yes, all you had to do was simply try it

Regards,
Peter T

"Marcolino" wrote in message
...
Would this also prevent a user from simply clicking on the X in the
top-right
corner of the userform, which simply ends the subroutine?

I can't seem to add a control to that X to prevent this from happening.

Thanks

"Peter T" wrote:

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?






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel VBA - Close Event for Password Userform Peter T Excel Programming 0 June 16th 09 10:04 PM
Userform in Before close event of workbook Raj[_2_] Excel Programming 4 June 30th 08 11:29 PM
Before Close Event Hide all Worksheets then Close Application RyanH Excel Programming 0 January 24th 08 03:15 PM
why does userform close after programming worksheet event with CreateEventProc or AddFromString tr00per Excel Programming 3 February 4th 06 10:09 PM
Close UserForm despite Exit Event Carim[_3_] Excel Programming 4 May 17th 05 05:39 AM


All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"