PDA

View Full Version : UserForm_Terminate



fgarcia90
07-24-2012, 04:49 AM
In this code


Private Sub UserForm_Terminate()
If MsgBox("Deseja sair sem gravar?", vbYesNo, "Criador de Produtos") = vbNo Then
form_user_inicial_tecnica.RedoAction
Else
Application.Quit
End If
End Sub


if user chose No it won't show the form again? why?

GTO
07-24-2012, 05:08 AM
A bit sloppy on my answer, but the Terminate event is happening as the Class/Object is being destroyed. That is, there is no really turning back.

Thus, I believe one would want to allow a delay, and initialize a new Class/Object. Maybe something like:

Option Explicit

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub UserForm_Terminate()
Dim uf As MSForms.UserForm

If MsgBox("Bring back?", vbYesNo, vbNullString) = vbYes Then
DoEvents
Application.OnTime Now + TimeValue("00:00:01"), "Reinstate"
End If
End Sub

GTO
07-24-2012, 05:10 AM
Sorry, 'ReInstate' would be in a Standar Module, like:
Option Explicit

Sub Reinstate()
UserForm1.Show
End Sub


Hope that helps,

Mark

fgarcia90
07-24-2012, 05:22 AM
Thanks with your help made like this work


Private Sub UserForm_Terminate()
If MsgBox("Deseja sair
sem gravar?", vbYesNo, "Criador de Produtos") = vbYes Then
Application.Quit
Else
DoEvents
Application.OnTime Now +
TimeValue("00:00:00"), "user_passa_a_seccao.seccao"
End If
End Sub