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.

How do I add text and form field2 if value is selected from dropdown field1?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Finlayson - 07 Jan 2005 22:16 GMT
I am creating a form that has several instances where the selection of a value
in a dropdown field should modify the form by adding text and in some cases
adding another form field. What code do I need to use for the macro?
Charles Kenyon - 10 Jan 2005 16:21 GMT
This may help get you started. You will need an on-exit macro for your
dropdown that checks its contents. What follows is an on-exit macro for a
checkbox that alters other fields. Hope it helps.

Sub DucesTecum()
'
' DucesTecum Macro
' OnExit macro for DucesTecum Checkbox
' "&chr(10)&"Macro recorded 05/16/2001 by Charles Kyle Kenyon
'
   Dim strBringWith As String, rRange As Range
   With ActiveDocument
       UnProtectSubpoena  'subroutine below
       Set rRange = .Bookmarks("YouBringYes").Range
       'Save result of form field
       strBringWith = .FormFields("BringWhat").Result
       If .FormFields("chkDucesTecum").CheckBox.Value _
           = True Then
           .FormFields("DucesTecumTitle").TextInput.EditType _
               Type:=wdRegularText, Default:=" Duces Tecum "
           If strBringWith = "" Then strBringWith = _
               "Bring what?" 'End If
           .FormFields("BringWhat").TextInput.EditType _
               Type:=wdRegularText, Default:=strBringWith, _
                   Enabled:=True
           rRange.Font.DoubleStrikeThrough = False
           rRange.Font.Bold = True
           .FormFields("BringWhat").Select
       Else
           .FormFields("DucesTecumTitle").TextInput.EditType _
               Type:=wdRegularText, Default:=" ", Enabled:=False
           .FormFields("BringWhat").TextInput.EditType _
               Type:=wdRegularText, Default:="", Enabled:=False
           rRange.Font.DoubleStrikeThrough = True
           rRange.Font.Bold = False
           .FormFields("chkThirdParty").Select
       End If
       .Protect wdAllowOnlyFormFields, True, sPass
   End With
End Sub

Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

>I am creating a form that has several instances where the selection of a
>value
> in a dropdown field should modify the form by adding text and in some
> cases
> adding another form field. What code do I need to use for the macro?
Steve Finlayson - 13 Jan 2005 05:13 GMT
I appreciate your reply. I hate to admit that I am still a novice and it is over
my head. Let me be more specific and see it that helps. I have created to macro
outlines using English and VBA to try to show what I am wanting to do. I think
if I understood them, I would be able to move on. They are as follows:

Sub1()
Select FormField (Text183)
If this is 9 then
At the end of the line TypeText Text: "New Text Here"
At the end of the line enter the value from FormField Text184 plus 2
Else
Reprotect Form
End Sub

Sub 2()
Select FormField (Text 194)
If item 2 is selected then
At the end of the line TypeText Text: "New Text 2 Here"
At the end of the line insert a Number Form Field
At the end of the line TypeText Text: "New Text 3 Here"
At the end of the Line insert a DropDown Form Field with choices: Text 1, Text
2, Text 3
Else
Reprotect Form
End Sub

I do not know how to state in VBA the textural portions of these and if my logic
is correct, is what I need to accomplish this. Any help would be appreciated.
Thanks
Steve

>This may help get you started. You will need an on-exit macro for your
>dropdown that checks its contents. What follows is an on-exit macro for a
[quoted text clipped - 36 lines]
>    End With
>End Sub
Charles Kenyon - 13 Jan 2005 15:02 GMT
Sorry, while I might be able to do this, it isn't something I can just snap
out and I don't have time right now to play with it. Hopefully, someone else
here will be able to give you more assistance.

Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

>I appreciate your reply. I hate to admit that I am still a novice and it is
>over
[quoted text clipped - 73 lines]
>>    End With
>>End Sub
Doug Robbins - 14 Jan 2005 00:17 GMT
If you store the text as an autotext entry, you could use this:

' Macro2 Macro

' Macro created 15-11-97 by Doug Robbins to add the address corresponding to
a drop down name

'

Set myDrop = ActiveDocument.FormFields("Dropdown1").DropDown

Company = myDrop.ListEntries(myDrop.Value).Name

Address = ActiveDocument.AttachedTemplate.AutoTextEntries(Company).Value

ActiveDocument.FormFields("Text1").Result = Address

End Sub

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Sorry, while I might be able to do this, it isn't something I can just
> snap out and I don't have time right now to play with it. Hopefully,
[quoted text clipped - 77 lines]
>>>    End With
>>>End Sub
Steve Finlayson - 17 Jan 2005 05:06 GMT
Doug,
Thank you. I think that will work for some of the instances. I have another
question that may work for the others.
Is there a way to delete the rest of a line if a specific value is chosen in a
dropdown? Something like using the first two lines in the code you provided and
then a line that deletes the rest of the line if selection 2 of 3 choices is
made.
Thanks
Steve

>If you store the text as an autotext entry, you could use this:
>
[quoted text clipped - 14 lines]
>
>End Sub
Steve Finlayson - 18 Jan 2005 17:29 GMT
Doug,
Can you help me apply your answer - I have an autotext entry xyz and a dropdown
value of 4 and 9. How do I specify that when 9 is selected the xyz text is
inserted? Where do I specify the dropdown triggering choice? And were do I
insert the Autotext name? Once I understand this, I think I am OK.

Thanks
Steve

>If you store the text as an autotext entry, you could use this:
>
[quoted text clipped - 10 lines]
>
>End Sub
 
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.