Hiding text depending on combobox

J

Jaco

Hi

I've got a form that populates fields in a document. On
the form is a combobox with two options. When one of the
options are selected, a piece of text must be hidden,
deleted, whatever, so long as it is not there.

On the other option that piece of text must be displayed.
Can somebody please tell me what is the easiest way to
hide and unhide the text, because the user might change
his mind.

The text is a heading, with 3 numbered points below it,
and Form Fields at each point. I need to keep the
formatting and numbering
 
P

Peter Hewett

Hi Jaco

There's two ways of tackling this:

1. You can bookmark both pieces of text and set the font attributes of one to Hidden =
True and the other block to Hidden = False.

2. You can use AutoText entries. Just create two empty bookmarks, one for each possible
text location. Delete the contents of the one you want empty (in case the user is
rerunning your code) and insert the contents of an AutoText entry in the other.

You can delete the contents of a Bookmark like this:
ActiveDocument.Bookmarks("BM1").Range.Text = vbNullString


You can use this code to insert an AutoText entry in a bookmark:

Public Sub InsertAutoText(ByVal strAutoTextName As String, _
ByVal strBookmarkName As String)
Dim tplAttached As Word.Template
Dim rngLocation As Word.Range

' Insert specified autotext at the bookmarked location
' and then recreate the bookmark
Set tplAttached = ActiveDocument.AttachedTemplate
Set rngLocation = ActiveDocument.Bookmarks(strBookmarkName).Range
Set rngLocation = tplAttached.AutoTextEntries(strAutoTextName).Insert(rngLocation,
True)
ActiveDocument.Bookmarks.Add strBookmarkName, rngLocation
End Sub


You call the code like this:
InsertAutoText "AutoText entry name", "Bookmark name"

HTH + Cheers - Peter
 

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