hidding font

B

bryan

Trying to hide <text2> and <text3> (same line, continuous) if <text1> is ""
so that when printing everything below text2 and 3 move up

Form is protected
Here's what I have but, I get "Requested member of collection does not exitst"
Sub tx1()
If ActiveDocument.FormFields("Text1").Result = "" Then
ActiveDocument.Unprotect
ActiveDocument.Styles("Text2").Font.Hidden = True
ActiveDocument.Styles("Text3").Font.Hidden = True
ActiveDocument.Protect wdAllowOnlyFormFields, Noreset
End If
End Sub

Help!

Thanks,
Bryan
 
D

Doug Robbins - Word MVP

You almost certainly will not have Styles named Text2 and Text3 in your
document.

The following code will hide the paragraphs in which Text2 and Text3 are
located:

With ActiveDocument
If .FormFields("Text1").Result = "" Then
.FormFields("Text2").Range.Paragraphs(1).Range.Font.Hidden = True
.FormFields("Text3").Range.Paragraphs(1).Range.Font.Hidden = True
End If
End With

BUT, if there is nothing entered in Text1, even though the selection will
appear to be in the next formfield, your users will have to press Tab 3 a
second and a third time before they can enter text into the next FormField,
though that could be reduced to 2 times if you use code to set the .Enabled
property of Text3 to false:

With ActiveDocument
If .FormFields("Text1").Result = "" Then
.FormFields("Text2").Range.Paragraphs(1).Range.Font.Hidden = True
With .FormFields("Text3")
.Range.Paragraphs(1).Range.Font.Hidden = True
.Enabled = False
End With
End If
End With

You SHOULD also tell the users to use UNDO if they inadvertently missed
entering something in Text1.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

Using

With ActiveDocument
If .FormFields("Text1").Result = "" Then
.FormFields("Text2").Range.Paragraphs(1).Range.Font.Hidden = True
.FormFields("Text3").Range.Paragraphs(1).Range.Font.Hidden = True
.FormFields("Text4").Range.Select
End If
End With

will eliminate the necessity for multiple tabs.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

bryan

Thanks Doug,
Works perfectly.
Why do I not have to unprotect the document? I thought I would need to since
it is protected.

Couple others:
Question 1 : I am a novice coding VB in Word, particularly the nuances of
Word objects.
Question2 : What is a good source to learing commands and coding for
doucuments?

Much appreciated,
Bryan
 
D

Doug Robbins - Word MVP

I guess I am a bit surprised that turning of the protection is unnecessary,
particularly if the paragraphs which contain the formfields, also contain
other text, which cannot be edited/accessed when the document is protected.

See the article "Getting To Grips With VBA Basics In 15 Minutes" at:

http://www.word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm

and other articles on that site.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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