Forms with Conditional Formating

S

saw185

I am trying to make a form that will change subsequent paragraph information
further down in the document based on selections in a drop-down list. Do you
have a suggestion on how I can accomplish this?
 
G

Greg Maxey

If the DD is in the first paragraph and you want to change the second
para then something like this:
Sub OnExitDD()
Dim oFF As FormFields
Dim oPar As Paragraphs
ActiveDocument.Unprotect
Set oFF = ActiveDocument.FormFields
Set oPar = ActiveDocument.Paragraphs
Select Case oFF("DropDown1").Result
Case "A"
oPar(2).Range.Text = "This is the first letter of the alphabet"
Case "B"
oPar(2).Range.Text = "This is the second letter of the alphabet"
Case "C"
oPar(2).Range.Text = "This is the third letter of the alphabet"
End Select
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End Sub
 
S

saw185

Thanks Greg. Now I have another problem.

The way the code is written, the next paragraph is the conditional
statement, i.e., "This is the XXX letter of the alphabet.

How do I place the conditional information at the start of a numbered
paragraph immediately following the Case or further down in the document
while maintaining the formating in between?

saw185
 
G

Greg Maxey

You cound bookmark an empty paragraph where you want the conditional text to
appear (e.g., MyPlace) and use something like:
Sub OnExitDD()
Dim oFF As FormFields
Dim oBMs As Bookmarks
Dim oRng As Range
ActiveDocument.Unprotect
Set oFF = ActiveDocument.FormFields
Set oBMs = ActiveDocument.Bookmarks
Set oRng = oBMs("MyPlace").Range
Select Case oFF("DropDown1").Result
Case "A"
oRng.Text = "This is the first letter of the alphabet"
Case "B"
oRng.Text = "This is the second letter of the alphabet"
Case "C"
oRng.Text = "This is the third letter of the alphabet"
End Select
oBMs.Add "MyPlace", oRng
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End Sub
 
S

saw185

When I tried to run the macro I got an error on the following:

Set oRng = oBMs("MyPlace").Range

Help.
 
G

Greg Maxey

Did you insert a bookmark in the document where you want the conditional
text to appear and name it "MyPlace"?
 
S

saw185

I added the Bookmark and now I have a "Complie error: Sub or Function not
defined" message. The highlighted area is oBMs in the "Set oRng = oBMs
("MyPlace").Range"

saw185
 
G

Greg Maxey

It works here.

E-mail me at (e-mail address removed)
remove CAPS
and I will send you a working document to try.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top