Delete bookmarked text from Word document using Access form checkbox control

I have a new document which launches from Access based off a Word template. Within the new document I have a text string, which I identify with a bookmark. My question...

I would like to be able to delete that entire text string if a checkbox on an access form is selected and if it is not selected not do anything with it. There will be a command button (on the Access Form)  onclick event that should run the code to accomplish this. Any ideas?
SherkanowskiAsked:
Who is Participating?
 
Simon BallCommented:
here's the word code to delete the contents of the bookmark, and th bookmark itself

Dim bkm As Bookmark

For Each bkm In ActiveDocument.Bookmarks

If bkm.Name = "w2" Then
MsgBox bkm.Name
bkm.Select '  selects the bookmarked parag
'deletes the selection
Selection.Delete Unit:=wdCharacter, Count:=1
'delete the bookmark
bkm.Delete

End If
Next bkm

within your word object code, you need to make this  like

(if the word object is called objword)

Dim bkm As Bookmark

For Each bkm In objword.ActiveDocument.Bookmarks

If bkm.Name = "w2" Then
MsgBox bkm.Name
bkm.Select '  selects the bookmarked parag
'deletes the selection
objword.Selection.Delete Unit:=wdCharacter, Count:=1
'delete the bookmark
bkm.Delete

End If
Next bkm

so for the oher question you could replace the selection with the new code.


then you also need to tie this to the access form so that it runs if the boton is clicked etc.
0
 
Simon BallCommented:
yes, you will have to launch the word document by opening an word object, passing it the document and then using vba code from access to drive word and have it find that string and delete it, or replace it with "" / null.

Private Sub Command1_Click()
dim string_to_find as string
Dim oApp As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

'then we record a marco within word, and place it in here to do the work.

'using

with oApp
.line1 - find the string
.lin2 - delete the string
end with
End Sub

i'll have a play with this for you tomorrow
0
 
SherkanowskiAuthor Commented:
I tried different things using your code but could not get it working
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Simon BallCommented:
i think we have to look at these one at a time, as your questions are touching upon similar area's..and i think the other one is progressing slowly.
0
 
SherkanowskiAuthor Commented:
This worked perfectly! Thank you!!
0
 
Simon BallCommented:
cool!¬  two down, one to go.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.