Command button problem

Discussion in 'Word Programming' started by Jason Lepack, Mar 9, 2007.

  1. Jason Lepack

    Jason Lepack Guest

    I have a document on which the requirement is to force users to enter
    data in specific fields in the top half of the first page and the
    header. The rest of the document must be freely editable.

    I created form fields in the page and then bookmarks in the header. I
    split the page into two sections and set allow only form entries in
    the first section.

    Now I can't modify the header because it's protected (which is what I
    want, because I don't want users accidentally deleting the bookmarks,
    things are too fragile...) so I created a command button to modify the
    header code is below:

    Private Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As
    String)
    On Error GoTo updBM_Err
    Dim BMRange As Range, doc As Document
    Set doc = ActiveDocument
    doc.Unprotect "toughpassword"
    Set BMRange = doc.Bookmarks(BookmarkToUpdate).Range
    BMRange.Text = TextToUse
    doc.Bookmarks.Add BookmarkToUpdate, BMRange
    doc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
    Password:="toughpassword"
    Exit Sub
    updBM_Err:
    If Err.Number = 4605 Then
    Resume Next
    Else
    MsgBox Err.Number & " - " & Err.Description
    End If
    End Sub

    ' Prompts the user to modify the header
    ' Called by command button
    Public Sub modifyHeader()
    Dim s As String
    s = InputBox("Enter a Title for your Document", , " ")
    If Not s = "" Then UpdateBookmark "Title", s
    s = InputBox("Enter a Document Number", , " ")
    If Not s = "" Then UpdateBookmark "DocNum", s
    s = InputBox("Enter a Revision Number", , " ")
    If Not s = "" Then UpdateBookmark "RevNum", s
    End Sub

    That worked great but the command button showed up on print.

    So I found the method of inserting the button into a text box and
    hiding the text box on print. That worked great too.

    Now here's the current problem. When I click my button I get the
    error at doc.protect:
    Err.Number = 4641
    Err.Description = The ToolsProtectDocument statement is currently
    disabled

    So with just the button, runs fine, button prints.
    Button in text box, button doesn't print, document won't reprotect.

    ANy help on this situation, including other methods, would be greatly
    appreciated. I've created lots of Excel and Access solutions, but
    this is my first Word Macro.

    Thanks,
    Jason Lepack
     
    Jason Lepack, Mar 9, 2007
    #1
    1. Advertisements

  2. Jason Lepack

    Jason Lepack Guest

    On Mar 9, 10:00 am, "Jason Lepack" <> wrote:
    > I have a document on which the requirement is to force users to enter
    > data in specific fields in the top half of the first page and the
    > header. The rest of the document must be freely editable.
    >
    > I created form fields in the page and then bookmarks in the header. I
    > split the page into two sections and set allow only form entries in
    > the first section.
    >
    > Now I can't modify the header because it's protected (which is what I
    > want, because I don't want users accidentally deleting the bookmarks,
    > things are too fragile...) so I created a command button to modify the
    > header code is below:
    >
    > Private Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As
    > String)
    > On Error GoTo updBM_Err
    > Dim BMRange As Range, doc As Document
    > Set doc = ActiveDocument
    > doc.Unprotect "toughpassword"
    > Set BMRange = doc.Bookmarks(BookmarkToUpdate).Range
    > BMRange.Text = TextToUse
    > doc.Bookmarks.Add BookmarkToUpdate, BMRange
    > doc.ProtectType:=wdAllowOnlyFormFields, NoReset:=True,
    > Password:="toughpassword"
    > Exit Sub
    > updBM_Err:
    > If Err.Number = 4605 Then
    > Resume Next
    > Else
    > MsgBox Err.Number & " - " & Err.Description
    > End If
    > End Sub
    >
    > ' Prompts the user to modify the header
    > ' Called by command button
    > Public Sub modifyHeader()
    > Dim s As String
    > s = InputBox("Enter a Title for your Document", , " ")
    > If Not s = "" Then UpdateBookmark "Title", s
    > s = InputBox("Enter a Document Number", , " ")
    > If Not s = "" Then UpdateBookmark "DocNum", s
    > s = InputBox("Enter a Revision Number", , " ")
    > If Not s = "" Then UpdateBookmark "RevNum", s
    > End Sub
    >
    > That worked great but the command button showed up on print.
    >
    > So I found the method of inserting the button into a text box and
    > hiding the text box on print. That worked great too.
    >
    > Now here's the current problem. When I click my button I get the
    > error at doc.protect:
    > Err.Number = 4641
    > Err.Description = The ToolsProtectDocument statement is currently
    > disabled
    >
    > So with just the button, runs fine, button prints.
    > Button in text box, button doesn't print, document won't reprotect.
    >
    > ANy help on this situation, including other methods, would be greatly
    > appreciated. I've created lots of Excel and Access solutions, but
    > this is my first Word Macro.
    >
    > Thanks,
    > Jason Lepack


    Anyone?
     
    Jason Lepack, Mar 12, 2007
    #2
    1. Advertisements

  3. Jason Lepack

    Thom R Guest

    I know it's a little late to reply to this dead thread, but it came top of my google search when I was looking for solutions for the same issue (i.e. Tools Protect Document statement disabled when trying to use a command button nested in a text box).

    The reason I wanted to put a command button in a text box in the first place was to enable me to hide it when printing the document, so this solution worked for my purposes, but may not for everyone.

    INSTEAD OF USING A TEXT BOX, USE A FORM FRAME.

    1. VIEW>TOOLBARS>FORMS

    2. CLICK "INSERT FRAME" ON TOOLBAR

    3. CUT & PASTE COMMAND BUTTON INTO FRAME

    4. CTRL+A INSIDE FRAME

    5. FORMAT>FONT

    6. CHECK "HIDDEN"

    7. VOILA! You now have a Command Button that is hidden from view when printing, but is still be usable in a protected form.

    > On Friday, March 09, 2007 9:00 AM Jason Lepack wrote:


    > I have a document on which the requirement is to force users to enter
    > data in specific fields in the top half of the first page and the
    > header. The rest of the document must be freely editable.
    >
    > I created form fields in the page and then bookmarks in the header. I
    > split the page into two sections and set allow only form entries in
    > the first section.
    >
    > Now I can't modify the header because it's protected (which is what I
    > want, because I don't want users accidentally deleting the bookmarks,
    > things are too fragile...) so I created a command button to modify the
    > header code is below:
    >
    > Private Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As
    > String)
    > On Error GoTo updBM_Err
    > Dim BMRange As Range, doc As Document
    > Set doc = ActiveDocument
    > doc.Unprotect "toughpassword"
    > Set BMRange = doc.Bookmarks(BookmarkToUpdate).Range
    > BMRange.Text = TextToUse
    > doc.Bookmarks.Add BookmarkToUpdate, BMRange
    > doc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
    > Password:="toughpassword"
    > Exit Sub
    > updBM_Err:
    > If Err.Number = 4605 Then
    > Resume Next
    > Else
    > MsgBox Err.Number & " - " & Err.Description
    > End If
    > End Sub
    >
    > ' Prompts the user to modify the header
    > ' Called by command button
    > Public Sub modifyHeader()
    > Dim s As String
    > s = InputBox("Enter a Title for your Document", , " ")
    > If Not s = "" Then UpdateBookmark "Title", s
    > s = InputBox("Enter a Document Number", , " ")
    > If Not s = "" Then UpdateBookmark "DocNum", s
    > s = InputBox("Enter a Revision Number", , " ")
    > If Not s = "" Then UpdateBookmark "RevNum", s
    > End Sub
    >
    > That worked great but the command button showed up on print.
    >
    > So I found the method of inserting the button into a text box and
    > hiding the text box on print. That worked great too.
    >
    > Now here's the current problem. When I click my button I get the
    > error at doc.protect:
    > Err.Number = 4641
    > Err.Description = The ToolsProtectDocument statement is currently
    > disabled
    >
    > So with just the button, runs fine, button prints.
    > Button in text box, button doesn't print, document won't reprotect.
    >
    > ANy help on this situation, including other methods, would be greatly
    > appreciated. I've created lots of Excel and Access solutions, but
    > this is my first Word Macro.
    >
    > Thanks,
    > Jason Lepack



    >> On Monday, March 12, 2007 3:23 PM Jason Lepack wrote:


    >> Anyone?



    >>> On Wednesday, May 30, 2007 10:03 AM Darko H wrote:


    >>> Hi Jason,
    >>>
    >>> I was looking earlier today at this site for a solution to a very similar problem but unluckily there was no answer to your question.
    >>>
    >>> My problem was that in the protected Word form document I was changing the content of the header and footer and after that when trying to re-protect a document back I was getting the same error "The ToolsProtectDocument statement is currently
    >>>
    >>> disabled". After some time I realised I had to select any form cell in the main document body before trying to protect the document again and this has worked. Here it is, the two liner I am talking about :
    >>>
    >>> ...
    >>>
    >>> ActiveDocument.FormFields(1).Select
    >>>
    >>> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    >>>
    >>> ...
    >>>
    >>>
    >>>
    >>> If not too late, I hope this will help you or maybe somebody else.
    >>>
    >>>
    >>>
    >>> Cheers
    >>>
    >>> Darko



    >>>> On Monday, September 20, 2010 9:18 AM Susie W wrote:


    >>>> thanks for putting in your solutions. Worked for me as well.
     
    Thom R, Jun 18, 2012
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cwebb
    Replies:
    1
    Views:
    117
    Jean-Guy Marcil
    Apr 27, 2006
  2. danka

    Command Button - does not work on

    danka, Jun 27, 2006, in forum: Word Programming
    Replies:
    1
    Views:
    168
    Cindy M -WordMVP-
    Jun 28, 2006
  3. Anne

    Command Button

    Anne, Jul 26, 2006, in forum: Word Programming
    Replies:
    1
    Views:
    94
    Jonathan West
    Jul 26, 2006
  4. Darko H

    Command button problem< roups.com>

    Darko H, May 30, 2007, in forum: Word Programming
    Replies:
    1
    Views:
    188
    Susie W
    Sep 20, 2010
  5. SP

    Coding Command Button Word 2007

    SP, Mar 7, 2008, in forum: Word Programming
    Replies:
    0
    Views:
    98
  6. tiah

    Using a command button in a protected form

    tiah, Apr 16, 2008, in forum: Word Programming
    Replies:
    1
    Views:
    86
  7. christophercbrewster via OfficeKB.com

    Running a Ppt command from Word - problem

    christophercbrewster via OfficeKB.com, Apr 20, 2009, in forum: Word Programming
    Replies:
    3
    Views:
    142
    christophercbrewster via OfficeKB.com
    Apr 20, 2009
  8. johnlute

    command button to save and then attach to email

    johnlute, Jul 2, 2010, in forum: Word Programming
    Replies:
    2
    Views:
    797
    johnlute
    Jul 6, 2010
Loading...