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 / January 2005

Tip: Looking for answers? Try searching our database.

Creation of a macro IF statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Finlayson - 19 Jan 2005 15:38 GMT
I am pretty weak in VB and need some basic help.
How do I create an IF statement within a macro that runs on exit from a dropdown
field? I have a field that has 3 or 4 choices and if one is selected I want to
call another macro to execute. I need to be able to simply say:
if choice 2 run mymacroname.
Thank you for the assistance.
Steve
Jean-Guy Marcil - 19 Jan 2005 15:59 GMT
Steve Finlayson was telling us:
Steve Finlayson nous racontait que :

> I am pretty weak in VB and need some basic help.
> How do I create an IF statement within a macro that runs on exit from
[quoted text clipped - 3 lines]
> if choice 2 run mymacroname.
> Thank you for the assistance.

Try this:

'_______________________________________
Sub CheckDropDown()

If ActiveDocument.FormFields("Dropdown1") _
   .DropDown.Value = 2 Then MyModule.ExecuteIf2

End Sub
'_______________________________________

'_______________________________________
Sub ExecuteIf2()

MsgBox "The second item was selected."

End Sub
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jean-Guy Marcil - 19 Jan 2005 18:09 GMT
In a personal reply, Steve Finlayson was telling us:

> When I try to step through the code you gave me if goes to the statement
> shown here
[quoted text clipped - 10 lines]
>  Thanks
> Steve

For everybody's benefit, it is better to reply to the group, unless you have
a special request.

   MyModule.ExecuteIf2
means that the macro called "ExecuteIf2" in the module called "MyModule"
will be executed.

Just change "MyModule" for the module name where "ExecuteIf2" is stored
(NewMacros? Module1? A module you named yourself?)

If the
   Sub CheckDropDown()
and the
   Sub ExecuteIf2()
are in the same module, you can use
   If ActiveDocument.FormFields("Dropdown1") _
       .DropDown.Value = 2 Then ExecuteIf2

It is just my habit of being thorough that made me write
   MyModule.ExecuteIf2

Cheers.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Steve Finlayson - 19 Jan 2005 19:26 GMT
I have done that and it goes to the end of the IF and appears to evaluate it as
a False and so ends. The dropdown1 shows 2 in the form. I have tried running it
with the form both protected and not with the same result. Am I missing
something in the form end of the process? The macro is in the module that is
part of the document holding the form and the dropdown1.

I really appreciate your help on this. Thanks
Steve

>In a personal reply, Steve Finlayson was telling us:
>
[quoted text clipped - 35 lines]
>
>Cheers.
Jean-Guy Marcil - 19 Jan 2005 19:58 GMT
Steve Finlayson was telling us:
Steve Finlayson nous racontait que :

> I have done that and it goes to the end of the IF and appears to
> evaluate it as a False and so ends. The dropdown1 shows 2 in the
> form. I have tried running it with the form both protected and not
> with the same result. Am I missing something in the form end of the
> process? The macro is in the module that is part of the document
> holding the form and the dropdown1.

What does the dropdown list consist of?
The Form must be protected and called from the on Exit event of the DropDown
form field.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Steve Finlayson - 19 Jan 2005 23:45 GMT
The options are: Select One, 4, 9. The form is protected and then I select the
number 4 and click on the next field. Nothing happens other than entering the
next field. The macros that I have stored in the NewMacro module are as follows:
Sub CheckDropDown2()

If ActiveDocument.FormFields("Dropdown1") _
   .DropDown.Value = 4 Then ExecuteIf4

End Sub

Sub ExecuteIf4()

MsgBox "The second item was selected."

End Sub

I am using Word 2002 and Win XP Pro.
Thanks
Steve

>Steve Finlayson was telling us:
>Steve Finlayson nous racontait que :
[quoted text clipped - 9 lines]
>The Form must be protected and called from the on Exit event of the DropDown
>form field.
Jean-Guy Marcil - 20 Jan 2005 06:21 GMT
Steve Finlayson was telling us:
Steve Finlayson nous racontait que :

> The options are: Select One, 4, 9. The form is protected and then I
> select the number 4 and click on the next field. Nothing happens
> other than entering the next field. The macros that I have stored in
> the NewMacro module are as follows: Sub CheckDropDown2()
>
> If ActiveDocument.FormFields("Dropdown1") _

>>>>>    .DropDown.Value = 4 Then ExecuteIf4

This should be:
   .DropDown.Value = 2 Then ExecuteIf4

.Value = 2 refers to the second item in the list, not the one that has a
string value of  "2".

By using the number 4 in a list of 3, the macro cannot find the fourth
element, therefore nothing happens.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Steve Finlayson - 20 Jan 2005 20:41 GMT
Thank you. I have learned a lot. It is working!

I now need only to unprotect the document as I run the second macro that deletes
a bookmarked piece of text and I am done. I think I have that code from when we
run the spell check. I will repost if I need more help.

Thanks
Steve

>Steve Finlayson was telling us:
>Steve Finlayson nous racontait que :
[quoted text clipped - 16 lines]
>By using the number 4 in a list of 3, the macro cannot find the fourth
>element, therefore nothing happens.
 
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.