Results 1 to 14 of 14
  1. #1
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Collapsing / Showing sections in a protected form

    I have a form template that must show (expand) more (duplicate) areas of a the form to fill out only if the user clicks a box. I start with 30 sections (in this case real estate deeds) all hidden, but the first. I use a macro to unprotect the document, then unhide a deed, then reprotect the document, If an x-box is checked

    The problem is, once hidden, a section never reappears. Can somebody tell me what I am overlooking?

    Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Collapsing / Showing sections in a protected form

    Welcome to Woody's Lounge!

    Could you post the code you're using?

  3. #3
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapsing / Showing sections in a protected f

    Sub d4bm()

    ActiveDocument.Unprotect

    Selection.GoTo What:=wdGoToBookmark, Name:="deed4"

    Selection.Font.Hidden = wdToggle

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
    NoReset:=True

    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Collapsing / Showing sections in a protected f

    The problem is that you can't "go to" the bookmark once it's hidden. Fortunately, you don't need to do so to unhide it:

    Sub d4bm()
    ActiveDocument.Unprotect
    ActiveDocument.Bookmarks("deed4").Range.Font.Hidde n = wdToggle
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End Sub

  5. #5
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapsing / Showing sections in a protected f

    Wow! that works! Thanks.

    Hey, do you know how to make a control button unhide bookmarks, (counting 1 through 29), or at least how to make a checkbox work when it is *checked* not entered or exited?

    Many thanks,
    Noah

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Collapsing / Showing sections in a protected f

    Is that a check box from the Forms toolbar, or from the Control Toolbox? Check boxes from the Forms toolbar don't react to immediately to being ticked/cleared, you can only specify a macro to be run on entry and on exit. Check boxes from the Control Toolbox can react immediately.

  7. #7
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapsing / Showing sections in a protected f

    this macro seems to have to do nothing when run from a control box, check box. hmm!?

    Private Sub Deed2_Click()
    ActiveDocument.Unprotect
    ActiveDocument.Bookmarks("deed2").Range.Font.Hidde n = wdToggle
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End Sub

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Collapsing / Showing sections in a protected f

    Have you made sure that you turned off design mode? The first button on the Control Toolbox should *not* be depressed.

    I wouldn't use wdToggle, but the value of the check box, to ensure that the visibility of the bookmark is synchronized with the state of the check box:

    Private Sub Deed2_Click()
    With ActiveDocument
    .Unprotect
    .Bookmarks("deed2").Range.Font.Hidden = Not .Deed2.Value
    .Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End With
    End Sub

  9. #9
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapsing / Showing sections in a protected f

    Man I am stuck. Will this file show you why the command button isn't doing anything?

    thanks,
    Noah
    Attached Files Attached Files

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Collapsing / Showing sections in a protected f

    The document that you attached doesn't contain any code. Perhaps you could zip the template it is based on and attach that?

  11. #11
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,549
    Thanks
    3
    Thanked 149 Times in 142 Posts

    Re: Collapsing / Showing sections in a protected f

    As Hans has pointed out, you have no code in the file you sent but the code you have seen earlier in the thread was based on a different document layout where there would be multiple checkboxes (one for each deed).

    I think that the checkbox adds complexity that the document doesn't need and would do the same thing with a macro like the following
    <pre>Sub AddDeed()
    Dim i As Integer
    With ActiveDocument
    .Unprotect
    For i = 1 To 4
    If .Bookmarks("deed" & i).Range.Font.Hidden Then
    .Bookmarks("deed" & i).Range.Font.Hidden = False
    Exit For
    End If
    Next i
    .Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End With
    End Sub</pre>

    To provide an interface handle for the user, you could use a macrobutton but I would add it below all your hidden text so that it is in the correct location for the user. The macrobutton field can be inserted by pressing Ctrl-F9 and typing the following between the field brackets
    macrobutton AddDeed Doubleclick to add another deed
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  12. #12
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapsing / Showing sections in a protected f

    I hope this works!

    -Noah
    Attached Files Attached Files

  13. #13
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapsing / Showing sections in a protected f

    Thanks Andrew! I'll have to try that. I am a real newbie at Word macros.

    -Noah

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Collapsing / Showing sections in a protected f

    1) The template is not protected for forms, so a document based on the template won't be protected either. Hence the first instruction in the code .Unprotect will fail.

    2) Your check box is named CheckBox1, but the code refers to a non-existing control named Deed2. You must use CheckBox1 instead of Deed2:

    .Bookmarks("deed2").Range.Font.Hidden = Not .CheckBox1.Value

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •