UserForm to AutoNew 
Author Message
 UserForm to AutoNew

I have a macro written in VBA with an AutoNew module and several UserForms.

The question is:
Does anyone know the code or know how to make the routine jump from a
CommandButton1_Click() routine in a Userform to a particular lable in a
AutoNew module after the UserForm unloads?

I have two buttons in the UserForm (Okay and Cancel)  The Okay button "
CommandButton1_Click() " will let the UserForm unload and continue in the
AutoNew module.  But I want the Cancel Button "CommandButton2_Click() " to
unload the UserForm, skip the rest of the routine and go to the label in the
Model called end:

Thanks



Thu, 28 Jul 2005 05:13:11 GMT  
 UserForm to AutoNew
Hi Gaderian,

Several ways
One of which:

Use a public boolean variable that scopes beyond modules.
In the AutoNew routine, turn it to False (it defaults to False but you never
know)
Then turn it to true when a users clicks on yr cancel button.
Userform unloads. Note: the variable now has True as a value.
In the AutoNew routine, build in a test after the UserForm.Show line
whether this variable is true or not. If True, jump to the code-bookmark
End.

I'll examplify it by a sequence of pseudo code lines

In a standard module general declaration section
Dim CancelClick As boolean

Sub AutoNew()
    CancelClick = False
    UserForm1.Show
    If CancelClick Then Goto End
    '<< other code >>
End:
    '<< code to be executed when CancelClick
End Sub

In your UserForm module
Private Sub cmdCancel_Click()
    '<< other code >>
    CancelClick = True
End Sub

Krgrds,
Perry



Quote:
> I have a macro written in VBA with an AutoNew module and several
UserForms.

> The question is:
> Does anyone know the code or know how to make the routine jump from a
> CommandButton1_Click() routine in a Userform to a particular lable in a
> AutoNew module after the UserForm unloads?

> I have two buttons in the UserForm (Okay and Cancel)  The Okay button "
> CommandButton1_Click() " will let the UserForm unload and continue in the
> AutoNew module.  But I want the Cancel Button "CommandButton2_Click() " to
> unload the UserForm, skip the rest of the routine and go to the label in
the
> Model called end:

> Thanks



Thu, 28 Jul 2005 05:43:22 GMT  
 UserForm to AutoNew
Thanks Perry!
I knew there was some way but forgot about the true and false values.


Quote:
> Hi Gaderian,

> Several ways
> One of which:

> Use a public boolean variable that scopes beyond modules.
> In the AutoNew routine, turn it to False (it defaults to False but you
never
> know)
> Then turn it to true when a users clicks on yr cancel button.
> Userform unloads. Note: the variable now has True as a value.
> In the AutoNew routine, build in a test after the UserForm.Show line
> whether this variable is true or not. If True, jump to the code-bookmark
> End.

> I'll examplify it by a sequence of pseudo code lines

> In a standard module general declaration section
> Dim CancelClick As boolean

> Sub AutoNew()
>     CancelClick = False
>     UserForm1.Show
>     If CancelClick Then Goto End
>     '<< other code >>
> End:
>     '<< code to be executed when CancelClick
> End Sub

> In your UserForm module
> Private Sub cmdCancel_Click()
>     '<< other code >>
>     CancelClick = True
> End Sub

> Krgrds,
> Perry



> > I have a macro written in VBA with an AutoNew module and several
> UserForms.

> > The question is:
> > Does anyone know the code or know how to make the routine jump from a
> > CommandButton1_Click() routine in a Userform to a particular lable in a
> > AutoNew module after the UserForm unloads?

> > I have two buttons in the UserForm (Okay and Cancel)  The Okay button "
> > CommandButton1_Click() " will let the UserForm unload and continue in
the
> > AutoNew module.  But I want the Cancel Button "CommandButton2_Click() "
to
> > unload the UserForm, skip the rest of the routine and go to the label in
> the
> > Model called end:

> > Thanks



Thu, 28 Jul 2005 12:22:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. AutoNew UserForm comes up before document?

2. UserForm updating a 2nd UserForm?

3. Two Questions - Making a userform active / Accessing a userform via a variable

4. How to center a Form to the UserForm it belongs to, if the UserForm has moved

5. How run AutoNew in a template in a webbrowser

6. AutoNew Macro

7. AutoNew: Run macro when new drawing is created?

8. Word VBA AutoNew macros fail to start

9. autoexec/autonew/customdocument properties

10. How to enforce autonew on Document1?

11. Programmatically create new document and NOT run AutoNew?

12. Autonew macro prompt

 

 
Powered by phpBB® Forum Software