View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
equiangular equiangular is offline
external usenet poster
 
Posts: 67
Default Userform Terminate

Hi,

You should use QueryClose event instead of Terminate event to cancel
closing the userform
Set Cancel to True to cancel closing

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
If (Me.BusName.Value) < "" Then
Dim ua As VbMsgBoxResult
ua = MsgBox("Do you wish to save the current data entered
on this form?", vbYesNo)
If ua = vbYes Then Cancel = True
End If
End If
End Sub


TimT wrote:
Hey Troops,
I would like to give the user the option to abort a Terminate (clicking the
red X) if they choose.
If there is data that the user input and they accidently terminate I was
trying to give the user the choice to abort the close and run another sub but
the form still closes and then runs the msgbox part of the code.

here's my code, any help would be greatly appreciated!!:

Private Sub UserForm_Terminate()

If (Me.BusName.Value) = "" Then
Unload Me
End If

If (Me.BusName.Value) < "" Then

Dim ua As String
ua = MsgBox("Do you wish to save the current data entered on this
form?", vbYesNo)
If ua = vbYes Then
Exit Sub
Else
If ua = vbNo Then
Unload Me
End If
End If
End If
End Sub