Clearing Form Fields on 1st Doc Open only?  
Author Message
dutchjm





PostPosted: Tue May 02 10:29:56 CDT 2006 Top

MS Word VBA >> Clearing Form Fields on 1st Doc Open only?

This seems it should be simple, but I'm spacing on it....

Hwo can I call the same macro from several Command Buttons without
having to copy the script to each Click() event?

So, I have a macro:

Sub ShowHello()
UserForm1.Show
End Sub

And let's just say I have three Command Buttons from which I would like
to launch the userform. Right now I would have:

CommandButton1_Click()
UserForm1.Show

CommandButton2_Click()
UserForm1.Show

CommandButton3_Click()
UserForm1.Show

So I end up having the script in 4 places; I know this is terribly
sloppy, but for some reason I'm just not conceiving of how to call the
other sub() macros from the buttons.....

Thanks!

Chris

Word219  
 
 
TomorrowsMan





PostPosted: Tue May 02 10:29:56 CDT 2006 Top

MS Word VBA >> Clearing Form Fields on 1st Doc Open only? Ugh, sorry - I had a different question and found an answer, but forgot
to change the Subject line.....

 
 
Jean-Guy





PostPosted: Fri May 05 06:10:34 CDT 2006 Top

MS Word VBA >> Clearing Form Fields on 1st Doc Open only? TomorrowsMan was telling us:
TomorrowsMan nous racontait que :

> This seems it should be simple, but I'm spacing on it....
>
> Hwo can I call the same macro from several Command Buttons without
> having to copy the script to each Click() event?
>
> So, I have a macro:
>
> Sub ShowHello()
> UserForm1.Show
> End Sub
>
> And let's just say I have three Command Buttons from which I would
> like to launch the userform. Right now I would have:
>
> CommandButton1_Click()
> UserForm1.Show
>
> CommandButton2_Click()
> UserForm1.Show
>
> CommandButton3_Click()
> UserForm1.Show
>
> So I end up having the script in 4 places; I know this is terribly
> sloppy, but for some reason I'm just not conceiving of how to call the
> other sub() macros from the buttons.....
>
> Thanks!
>
> Chris

Try:
CommandButton1_Click()
DoCodeSub
End Sub

CommandButton2_Click()
DoCodeSub
End Sub

CommandButton3_Click()
DoCodeSub
End Sub

Sub DoCodeSub()
Dim MyForm as UserForm1
Set MyForm = New UserForm1
MyForm.Show
'Do other stuff
Set MyForm = Nothing
End Sub

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP

Word MVP site: http://www.word.mvps.org