View Single Post
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman
 
Posts: n/a
Default How to create 'command buttons' to hide/reveal text in Word?

Hi Paul,

To initialize the controls of the userform to values in the bookmarks
to enable editing of previous entries, you need to grab those values
as the userform is preparing its appearance.

In the userform's code window in the VBA editor, there are two
dropdowns just below the toolbars. In the left dropdown, choose
"UserForm"; then in the right dropdown, choose "Activate". That
prepares this empty subroutine:

Private Sub UserForm_Activate()

End Sub

Between those lines, you can write code that will initialize the
contents of the text and combo boxes of the userform with whatever
values are in the bookmarks in the document. Here is sample code:

Private Sub UserForm_Activate()
Dim Depts As Variant
Dim strDept As String
Depts = Array("Sales", "Production", "Acquisitions")

' fill in text box
txtName.Text = _
ActiveDocument.Bookmarks("Name").Range.Text

' initialize combo box list and select value
With cbxDept
.Clear
.List = Depts
strDept = _
ActiveDocument.Bookmarks("Department").Range.Text
.Value = strDept
If Not .MatchFound Then
MsgBox "Invalid department " & strDept, _
vbOKOnly + vbCritical, "Error"
End If
End With
End Sub

Real working code should take into account the possibilities that the
bookmarks don't exist (the user deleted them or overwrote them) or
contain either nothing or invalid values.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Sat, 18 Feb 2006 10:36:26 -0800, "Paul Bishop"
wrote:

Thanks. I managed to run the example at
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

My users will have multiple data items from the left side, right side, both
or neither. I suppose that if I put all the relevant text and combo boxes
into a userform, on returning I can populate the two [sets of] bookmarks in
the document appropriately. It would be nice, if the user realises that he
has made a mistake, for him to be able to return to the userform and edit the
data fora second pass.
--
Paul Bishop


"Graham Mayor" wrote:

No you can't do that. You'll have to rethink the whole form in order to do
this. You can insert texts based upon the result of a form field eg
http://www.gmayor.com/SelectFile.htm but extra form fields are a different
matter. I would personally approach this using userforms and macros to call
further userforms based on the responses to create the finished document.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Paul Bishop wrote:
Yes, but would you recommend this approach if the text to be hidden
were a whole paragraph, itself containing several form fields?

See http://gregmaxey.mvps.org/Toggle_Data_Display.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Graham Mayor wrote:
My old pal and fellow MVP Greg Maxey did some work on this a while
back. See if there is anything on his web site that would help.
http://gregmaxey.mvps.org/
I am working off line at the moment and have cleared my internet
cache so you can check just as quickly as I can


tligett wrote:
I am needing to insert buttons that answer questions in a Word
document already heaviy ladden with macros. The yes/no answers
need to create a reaction where designated text is hidden
dependent on the answer to the question. I am told to use Visual
Basic Editor but am having a hard time setting the document up.
What do I do?