Consulting

Results 1 to 7 of 7

Thread: Solved: Userform in Word - Event to follow unload using Titlebar Close button

  1. #1
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location

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

    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:

    [VBA]
    '
    '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
    '
    [/VBA]

    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...

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

    Scott
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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...

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

    I'm not sure if this event is triggered even if the form is closed "legally" though, but I would expect it is...
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    Try out this one:

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

  4. #4
    Just A Dude VBAX Tutor Scottie P's Avatar
    Joined
    May 2004
    Location
    Remote from 18901 USA
    Posts
    263
    Location
    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!

    Scott
    Life is Visual: Presence is Perception...
    How we see the world is how we respond to it. ~* Peace *~

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    Ken, I know that just too well.
    BTW, it's quite to create a userform that can't be closed the normal way using QueryClose, just to terrorize "my special friends" .

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hey Scott!

    How lame should we feel now... look here!

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •