Disable Form Terminate

  • This is my first post so hopefully I am doing it right.


    How do I keep a UserForm from being terminated (similar to using 'Cancel = True' on the Workbook Close event)? That option isn't available with a Form. I want them to close it with the button I have provided so that the data will all be processed correctly.

    [COLOR="Red"][SIZE="3"]Semper Fi[/SIZE][/COLOR] :rambo:


    [SIZE="1"]Why programmers get Holloween and Christmas mixed up: OCT31 = DEC25[/SIZE]

  • Re: Disable Form Terminate


    You would want to use the QueryClose Event of the form

    Code
    1. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    2. Select Case CloseMode
    3. Case 0 'user clicked X
    4. Cancel = True
    5. End Select
    6. If Cancel = True Then
    7. MsgBox "Cannot Close Form In This Manner"
    8. End If
    9. End Sub


    There are other CloseModes available, if you wanted to test for those as well

  • Re: Disable Form Terminate


    Hi Nathan,


    Welcome to the forum.


    You need to have a look at QueryClose - you will see in the example below that it has a Cancel option.

    HTH

  • Re: Disable Form Terminate


    Hi Nathan and all others:


    i have this one liner that does the job.....


    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = 0 Then Cancel = True
    End Sub


    & then Use Logic to include buttons that will allow only predefined actions by you....This is one good method of NOT BEING Flexible....lol


    Hope this helps
    Regards
    Shubh