Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Exiting a Sub in Word 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alan Stancliff - 08 Mar 2008 10:02 GMT
Here's another VBA question for the Word 2003 macro experts.

Suppose I have a macro like this:

    Sub MyWondrousInvention()
        Userform_1_FRM.Show
        Userform_2_FRM.Show
    End Sub

As you can guess, the two items that "Show" are two user forms. The
first user form has a CANCEL button on it, and the code looks like this:

    Private Sub ExitCMD_Click()
        Userform_1_FRM.Hide
        Unload Userform_1_FRM
    End Sub

What I would like is that if the first user form exits because the
CANCEL button is pressed, the second user form does not and the
MyWondrousInvention sub is exited without the second step being
activated. But because the click routine is private, I can't figure out
how to make it abort the rest of the sub. I suppose some if-else-then
routine, but how does one do it in this case?

Regards,

Alan Stancliff
Graham Mayor - 08 Mar 2008 10:35 GMT
Wouldn't it make more sense to have

Sub MyWondrousInvention()
Userform_1_FRM.Show
End Sub

and

Private Sub ExitCMD_Click()
Unload Me
Userform_2_FRM.Show
End Sub

with additional sub routines called as required from each of the two user
forms?

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Here's another VBA question for the Word 2003 macro experts.
>
[quoted text clipped - 23 lines]
>
> Alan Stancliff
Alan Stancliff - 08 Mar 2008 20:10 GMT
Hi Graham,

Yup, it probably would make more sense. I'm going to play with it a bit
more tonight after work (I work weekends).

Thanks.

Regards,

Alan Stancliff

> Wouldn't it make more sense to have
>
[quoted text clipped - 11 lines]
> with additional sub routines called as required from each of the two user
> forms?
Alan Stancliff - 09 Mar 2008 08:40 GMT
I got it working now, Graham. It was much simpler than I thought. I
thought I would have to figure out some way of passing a value from a
private sub that was not even a function to a public one.

Regards,

Alan Stancliff

> Wouldn't it make more sense to have
>
[quoted text clipped - 11 lines]
> with additional sub routines called as required from each of the two user
> forms?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.