Question : How to delete a word bookmark when the document is launched from an Access form?

How can I delete a bookmark after text has been written to a word document?  I have produced a form where I can populate my chosen data in a word document.  I want to create a triple state condition where certain bookmarks are deleted based on the BalanceDue field in my form.  I have tried creating a macro in word and it produces the below VB code.  and tried to test with just the value of 1 field (in this case CheckNumber is null)... Anyway when I insert the code below my With doc statements the bookmarks remain.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
If Nz(Me![CheckNumber]) Is Null Then
    Selection.GoTo What:=wdGoToBookmark, Name:="ZERO"
    With ActiveDocument.Bookmarks
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.GoTo What:=wdGoToBookmark, Name:="CHECK"
    With ActiveDocument.Bookmarks
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
    Selection.Delete Unit:=wdCharacter, Count:=1
End If

Answer : How to delete a word bookmark when the document is launched from an Access form?

Somewhere is the code you should get the opportunity to capture the word document into an object variable as I demonstrate in the snippet. Then you can use the variable (wdDoc in the snippet)  directly.
1:
2:
3:
4:
5:
6:
7:
8:
9:
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
'...
Set wdDoc = wdApp.Documents.Add("C:\MyTemplatesFolder\MyTemplate.dot")
'...
If Nz(Me![CheckNumber]) Is Null Then
    wdDoc.Bookmarks("ZERO").Delete
    wdDoc.Bookmarks("CHECK").Delete
End If
Random Solutions  
 
programming4us programming4us