PDA

View Full Version : Solved: Userform in Word - Event to follow unload using Titlebar Close button



Scottie P
03-22-2005, 11:11 PM
ok...this has to be something obvious since I haven't been able to figure it out. I ask this question with the knowledge that I will be kicking myself as soon as I see the answer.

What I would like to do is have an event fired when a userform is closed (via the Red X on the Title Bar of the userform). Is this easy enough? I have never attempted to run a process in this manner, so I have no idea if this is even a 'legal' measure. My initial instinct is to set it up like:


'
'This is not good code! Do not attempt this at home!
'
Private Sub Userform_whatgoeshere?() '<-need this part and...
The userforms now closing so... '<-... I need this part as well
DoEvent '<-placed here to indicate that this is where we pick up again (will not actually be used)
Selection.GoTo What:=wdGoToBookmark, Name:="bkmk1"
End Sub
'


I have spent some time reading through the Newsgroups tonight, but haven't hit anything quite like this. There is other code in the document but certainly nothing that would interfere or be interfered with. Just need this last piece of my sorted and twisted puzzle...:bug:

Them be the basics. What fundamental piece did I grossly overlook? :rotlaugh:
No hurry on this and thank you for taking the time!

Scott

Ken Puls
03-22-2005, 11:21 PM
Hi Scott,

I know I've seen something on this before, but I can't remember where. I'm sure that I've read a procedure which evaluates if the user clicked the cancel button then returns them to the form...

In the mean time, maybe this will help...

Private Sub UserForm_Terminate()
MsgBox "OMG! You terminated me and I'm not even a KB entry!"
End Sub

I'm not sure if this event is triggered even if the form is closed "legally" though, but I would expect it is...

Steiner
03-22-2005, 11:24 PM
Try out this one:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then MsgBox "That tickles"
End Sub

Scottie P
03-22-2005, 11:33 PM
I really hate it when the obvious escapes me...

Thank you Kpuls and Steiner - both work equally well and now I have 'CloseModes' to play with!
This item is solved! :hi:

Scott

Ken Puls
03-22-2005, 11:44 PM
Thanks, Steiner! I think I must have been thinking of the inputbox function actually.

I've been playing with WebQueries most recently, so assumed that the QueryClose was sort of related to that, not that it was trying to figure out how the form was closed! LOL!

That's a good one to know! :yes

Steiner
03-23-2005, 07:09 AM
Ken, I know that :omg2: just too well.
BTW, it's quite :funnyashe to create a userform that can't be closed the normal way using QueryClose, just to terrorize "my special friends":neener: .

Ken Puls
03-24-2005, 10:57 PM
Hey Scott!

How lame should we feel now... look here (http://www.vbaexpress.com/kb/getarticle.php?kb_id=164)!

:doh: