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 / February 2007

Tip: Looking for answers? Try searching our database.

Deleting bookmarks doesn't work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 13 Feb 2007 14:09 GMT
Hi,

I have a template with 2 formfields containing the following
bookmarks:

- Name
- Place

The formfields are filled using a userform:

ActiveDocument.FormFields("Name").Result = Formname.Controls(Name)
ActiveDocument.FormFields("Place").Result = Formname.Controls(Place)

Then I want to insert a 'new page section' and in the new section I
want to insert the same template again, with thus the same bookmarks.
To prevent multiple bookmarks with the same name, I delete all
bookmarks before I make the new page section using:

ActiveDocument.Bookmarks("Name").Delete
ActiveDocument.Bookmarks("Place").Delete

I then insert the template on the second page.

What I want is to use the userform again to now fill the bookmarks on
the second page. However, if I use

ActiveDocument.FormFields("Name").Result = Formname.Controls(Name)
ActiveDocument.FormFields("Place").Result = Formname.Controls(Place)

again (assuming the Name bookmark is now on the second page due to the
template and having deleted all other bookmarks), the formfields on
the 1st page are filled again in stead of the second page.

It looks like the bookmark from the first page is not entirely
deleted! If I however unprotect the page and look in the property of
the formfield of the first page, there is no bookmark!

Can someone help me please?

Thanks, Mike
Greg Maxey - 13 Feb 2007 15:52 GMT
> Hi,
>
[quoted text clipped - 36 lines]
>
> Thanks, Mike

Mike,

I don't have a solution for you, but I can show that deleting the
bookmark associated with a formfield does "not" change the formfield
name.  In a new document insert on text formfield and then run the
following code:

Sub Scratchmacro()
With ActiveDocument
 .Bookmarks("Text1").Delete
 MsgBox .FormFields(1).Name
 .FormFields("Text1").Result = "Some text"
End With
End Sub
Mike - 14 Feb 2007 10:07 GMT
> > Hi,
>
[quoted text clipped - 53 lines]
>
> - Tekst uit oorspronkelijk bericht weergeven -

Thanks, but thats not what I'm looking for. Also tried to change the
name of the field, no luck....

Anyone else?

Mike
Jean-Guy Marcil - 14 Feb 2007 16:01 GMT
Mike was telling us:
Mike nous racontait que :

>>> Hi,
>>
[quoted text clipped - 61 lines]
>
> Mike

Instead of renaming the formfields already in place, you should rename the
one you just inserted in the document before you fill them out with text.
The reason being that if you insert formfields that have the same name as
exiting formfields, Word will internally choke and if you try to run simple
code like:

    myFormField.Name = "Test" & i

Word will return an error on those fields that had conflicting names.

There is a workaround (my code below) but that removes the formfield content
and resets it to its default value. This is fine with fresh formfields that
do not have content yet, but not with existing ones.

'_______________________________________
Sub RenameFormfields()

Dim lngSecNumber As Long

If Selection.Sections.Item(1).Index = 1 Then
   MsgBox "You cannot use this procedure from the first section in the
document."
   Exit Sub
End If

lngSecNumber = Selection.Sections.Item(1).Index

With ActiveDocument.Sections(lngSecNumber).Range
   .FormFields(1).Select
   With Dialogs(wdDialogFormFieldOptions)
   .Name = "Name" & lngSecNumber
       .Execute
   End With
   .FormFields(2).Select
   With Dialogs(wdDialogFormFieldOptions)
   .Name = "Place" & lngSecNumber
       .Execute
   End With
End With
'_______________________________________

But, if you use a "clean" system, you can use something like:

   myFormField.Name = "Test" & i

For that to Work, create an Autotext with the formfields, the text and the
section break and name those formfields "Name" and "Place".

Insert them in the first section and run code like:

'_______________________________________
Dim lngSecNumber As Long

lngSecNumber = Selection.Sections.Item(1).Index

With ActiveDocument.Sections(lngSecNumber).Range
   .FormFields(1).Name = "Name" & lngSecNumber
   .FormFields(2).Name = "Place" & lngSecNumber
End With
'_______________________________________

Every time you insert a new section, run the code to rename the formfields.
This way you will never have conflicting names.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Mike - 15 Feb 2007 17:16 GMT
> Mike was telling us:
> Mike nous racontait que :
[quoted text clipped - 138 lines]
>
> - Tekst uit oorspronkelijk bericht weergeven -

Thanks, you helped me a great deal!

Mike
 
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.