View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Userform Terminate

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


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"TimT" wrote in message
...
Joel,
Thanks for the quick response.
I might have the order wrong or something here.
When X is clicked, the form unloads immediately and then the messagebox
prompts the user. By that time, regardless of what the user answers to the
prompt the form has already closed and the data is lost.
Am I not catching the event correctly?
I wanted to the form to stay open until the user answers Yes or No so the
data can be saved and the user can have a chance to click the save button.

"Joel" wrote:

A mesbox returs a test string not vbYesNo. the ascii string need to be
compared using the strcomp() function

if strcomp(ua,"YES") then

You also want to convert the response to either lower case or upper case.

better
if strcomp(strconv(ua,vbUpperCase),"YES") = 0 then

"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