Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Command button problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Lepack - 09 Mar 2007 14:00 GMT
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 - 12 Mar 2007 21:23 GMT
> 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
[quoted text clipped - 61 lines]
> Thanks,
> Jason Lepack

Anyone?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.