none
hving problems concerning bookmarks :( RRS feed

  • Question

  • hi, i hve a big prob :(

    i hve bookmark in my table, n there r reference fields to them

    if ever user delete a bookmark, the references to the bookmark will b pointing to non existing bookmark

    which isnt gud to see in a doc

    so my questions are:

    is there a way to know which bookmark was deleted so as to delete the reference fields linked to it as well inorder not to get the error???

    or is there a way to prevent user from being able to delete the bookmark, i.e protect it???

    plz help if sme1 has an idea

    thks in advance :)

    Mush

    Tuesday, December 14, 2010 5:15 AM

Answers

  • Hi Mush,

    The ref field that produces the error message will still have the bookmark name. To see it, select the error message and press Shift-F9. You should see a field that look like {REF Bookmark}, where 'Bookmark' is the name of the deleted bookmark. To prevent this sort of thing from happening, you can put whatever you're referring to (provided it's text) into a custom document property and using a DOCPROPERTY field to refer to it wherever you want the material to appear. That way, there's no bookmark to delete.


    Cheers

    macropod MS MVP - Word

    • Proposed as answer by Bessie Zhao Tuesday, December 21, 2010 9:34 AM
    • Marked as answer by Bessie Zhao Thursday, December 23, 2010 9:55 AM
    Wednesday, December 15, 2010 8:25 AM

All replies

  • AFAIK you are developing using Word 2002. If so, I really do not think there is a way to do this. If you were using Word 2007 or later, you could consider putting your referenced items in content controls that you marked so that the users could not easily delete them. If you're using VSTO+Word 2007, the VSTO Bookmarks have some events that the ordinary Word Bookmarks do not have, but I don't think they include a deletion Event.

     


    Peter Jamieson
    Tuesday, December 14, 2010 11:04 AM
  • Hi Mush

    About the only thing that occurs to me is to try tracking whether the user has selected a bookmark using the WindowSelectionChange event. When the user selects and deletes, the event will be triggered (but not when the user types).

    You'll notice that the sample code below tracks if the selection triggered by the event has a bookmark and what the bookmark name is. The next time the event is triggered, the code checks whether the previous selection contained a bookmark. If that was the case, the code then checks whether that bookmark still exists in the document. If it does not, then you need to call the code to delete the references.

    'code in a class module named clsEvents
    Public WithEvents app As word.Application
    
    Private LastSelHadBookmark As Boolean
    Private LastBookmarkName As String
    
    Private Sub app_WindowSelectionChange(ByVal Sel As Selection)
      Dim doc As word.Document
    
    'Test deletion of bookmarks
      Set doc = Sel.Document
      Debug.Print Sel.Text, Sel.Bookmarks.Count
      If LastSelHadBookmark Then
        LastSelHadBookmark = False
        If Not doc.Bookmarks.Exists(LastBookmarkName) Then
          'Delete the references
          MsgBox "Deleting the references for bookmark " & LastBookmarkName
        End If
      End If
      If Sel.Bookmarks.Count > 0 Then
        LastSelHadBookmark = True
        LastBookmarkName = Sel.Bookmarks(1).Name
        doc.Variables("TrackBkmName").value = LastBookmarkName
      Else
        LastSelHadBookmark = False
      End If
    
    End Sub
    
    'code in a normal module to start/stop the events
    Public myEvents As New clsEvents
    
    Public Sub StartEvents()
      Set myEvents.app = word.Application
    End Sub
    
    Public Sub EndEvents()
      Set myEvents.app = Nothing
    End Sub
    
    

    Cindy Meister, VSTO/Word MVP
    Tuesday, December 14, 2010 11:47 AM
    Moderator
  • You could use the following field construction where you want the cross references to appear

    { if { REF [bookmarkname] } = “Error! Reference source not found.” “” { REF [bookmarkname] } }

    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "StarMush" wrote in message news:8f696a12-f38d-4290-abb8-3b229a684610@communitybridge.codeplex.com...

    hi, i hve a big prob :(

    i hve bookmark in my table, n there r reference fields to them

    if ever user delete a bookmark, the references to the bookmark will b pointing to non existing bookmark

    which isnt gud to see in a doc

    so my questions are:

    is there a way to know which bookmark was deleted so as to delete the reference fields linked to it as well inorder not to get the error???

    or is there a way to prevent user from being able to delete the bookmark, i.e protect it???

    plz help if sme1 has an idea

    thks in advance :)

    Mush


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Tuesday, December 14, 2010 10:17 PM
  • thks u all 4  ur replies

    i didnt hve the bookmark name

    cauz when the client deletes it u dnt hev a ny reference to the bookmark

    but i found a soln for my prob

    1st case: the [a] in the table had the bookmark

    2nd case: the [a]  explanation below table had a SEQ field

    n in zat the code.text of zat SEQ field i had the bookmark in my 1st case

    so i just retrieve zat bookmark name from the text then search it in the bookmarks

    if not found meaning bookmark was deleted

    hence delete all ref fields to it

    thks once again 4 ur answers, can use it next time when i wnt hve z soln i used in my case

    :)

    Mush

    Wednesday, December 15, 2010 5:21 AM
  • Hi Mush,

    The ref field that produces the error message will still have the bookmark name. To see it, select the error message and press Shift-F9. You should see a field that look like {REF Bookmark}, where 'Bookmark' is the name of the deleted bookmark. To prevent this sort of thing from happening, you can put whatever you're referring to (provided it's text) into a custom document property and using a DOCPROPERTY field to refer to it wherever you want the material to appear. That way, there's no bookmark to delete.


    Cheers

    macropod MS MVP - Word

    • Proposed as answer by Bessie Zhao Tuesday, December 21, 2010 9:34 AM
    • Marked as answer by Bessie Zhao Thursday, December 23, 2010 9:55 AM
    Wednesday, December 15, 2010 8:25 AM
  • thks macropod,

    did smething like zat wiz the SEQ field to get the deleetd bookmark

    :)

    Thursday, December 16, 2010 11:01 AM