Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Form replaced by bookmarks (Word 97)

    I have a document with a cover done in forms. The cover has Text Form Fields that are: Fill enabled and activate a macros that will pop-up the Entry Form. when I complete the form and click OK, the bookmark content drops into the cover. But, the Form Fields are completely removed and replaced by the bookmark. I just wanted the field to be populated, no replace... what do I need to do so that the form fields remain? - I think I'm close, but... <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Form replaced by bookmarks (Word 97)

    What is your code to assign the text to the form field? I think if you assign it to the .Result property, the field will not be wiped out, but that's from memory. (Also, if your form is protected, I think the .Result is one of the few properties that you can modify without a runtime error.)

  3. #3
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Form replaced by bookmarks (Word 97)

    I've attached a zip file. Though I have to admit that I'm only 85% familiar with the code, for I'm a beginning VBAer and I used something from another template, modified it and dropped it into my Temp. Basically, It reads the input from the form (txt), drops the tst and replaces it with bmk (bookmark) and searches the doc to replace the bookmarks. To make my situation a lil more involved, I'm wanting to protect the cover (section 1). And the last item, I know there's a line or 2 of code that can be added to read the bookmarks and populate the form, but I don't know where or what. - To modify the cover, click Cover Information from the SLC toolbar. A form will pop-up. ..... jody
    Attached Files Attached Files

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Form replaced by bookmarks (Word 97)

    Okay, here's the deal. Behind the UserForm is the code that runs when the OK button (which has a "name" of cmdOK and a "caption" of OK) is clicked. It looks like this:

    <pre>Private Sub cmdOK_Click()
    Unload Me
    WriteBookmarkText BookmarkName:="bmkProjectTitle", Text:=txtProjectTitle.Text
    WriteBookmarkText BookmarkName:="bmkQualifyTitle", Text:=txtQualifyTitle.Text
    WriteBookmarkText BookmarkName:="bmkDocType", Text:=txtDocType.Text
    WriteBookmarkText BookmarkName:="bmkVersionNum", Text:=txtVersionNum.Text
    WriteBookmarkText BookmarkName:="bmkDocNum", Text:=txtDocNum.Text
    End Sub</pre>

    WriteBookmarkText is not a built-in Word command, it's a procedure in one of the other modules that overwrite the FORMTEXT field, as the code notes:

    <pre>Public Sub WriteBookmarkText(BookmarkName As String, Text As String)
    ' this actually replaces the bookmark
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:="Blue"
    End If
    ActiveDocument.Bookmarks(BookmarkName).Range.Selec t
    With Selection
    .Text = Left(Text, Len(Text)) '- 2)
    .Bookmarks.Add _
    Name:=BookmarkName, _
    Range:=.Range
    End With
    End Sub</pre>

    To preserve the field, you can change the WriteBookmarkText procedure to the following. For safekeeping, name the existing one something like WriteBookmarkTextOld, and then add this one to the same module:
    <pre>Public Sub WriteBookmarkText(BookmarkName As String, Text As String)
    ' Substitute the new text for the field result
    ActiveDocument.FormFields(BookmarkName).Result = Text
    End Sub</pre>

    I realize that seems impossibly simple by comparison, but I tested it and it does work. The document remains protected, however, which is different. If you only want the cover to be protected, you can uncheck Section 2 in the Tools|Protect|Sections... subdialog.

    Uh-oh, there is a problem. I can't update the TOC - in Section 2 - while Section 1 is protected. If I unprotect the document and update the TOC, I lose the text input on the cover. Perhaps that's why the macros were set up as they were??

    Okay, here is a TOC updating macro:
    <pre>Sub RefreshTOC()
    With ActiveDocument
    .Unprotect Password:=""
    Dim toc As TableOfContents
    For Each toc In .TablesOfContents
    toc.Update
    Next
    .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
    End With
    End Sub</pre>

    You will need to fill in the relevant password, if any.

    I'm pooped! Hope this helps.

  5. #5
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Form replaced by bookmarks (Word 97)

    I renamed my "WriteBookmarkText" to OLD... and created a new WriteBookmarkText according to your suggestion:
    Public Sub WriteBookmarkText(BookmarkName As String, Text As String)

    ' Substitute the new text for the field result
    ActiveDocument.FormFields(BookmarkName).Result = Text

    But I get an error: "Requested member of the collection does not exist."

    - J <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Form replaced by bookmarks (Word 97)

    <hr>I get an error: "Requested member of the collection does not exist."<hr>
    You would expect to get this error if you have called the procedure using the name of a bookmark that doesn't exist. Can you try to...

    <UL><LI>Set a breakpoint just before the line <font color=blue>ActiveDocument.FormFields(BookmarkName) .Result = Text</font color=blue>
    <LI>Type the following commands in the VBE Immediate window
    <pre>? BookmarkName
    ? ActiveDocument.FormFields(BookmarkName)
    </pre>
    [/list]StuartR

  7. #7
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Form replaced by bookmarks (Word 97)

    It shows my correct bookmark and everything..... but still gives me the error! And thanks for the "immediate Window"!!!! That's Awesome.... the simple things that are already around us make life exciting, HEHEHEHE <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>

Posting Permissions

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