clear bookmark without deleting the bookmark

D

Dingbat

How can I clear the contents of a bookmark without removing the actual
bookmark.

I am populating a word document with records from an access database, then
printing the document, then moving onto the next record in the database and
repeating the exercise. However, each time I move on a record I add the text
next to the previous text rather than overwriting it.

Any help/suggestions will me much appreciated. Here is a portion of the code
I am currently using:

Do Until rst.EOF

With ActiveDocument

.Bookmarks("MailAddress").Range _
.InsertBefore rst!MailingAddr

.Bookmarks("TotalAmount").Range _
.InsertBefore FormatCurrency(rst!TotAmount, -1)


.Bookmarks("CurrentAnnualAmount").Range _
.InsertBefore rst!CurrentAnnualAmt

.Bookmarks("Description").Range _
.InsertBefore rst!Description

.Bookmarks("bkDate").Range _
.InsertBefore Date

If Not IsNull(rst!Arrears) And rst!Arrears > 0 Then
strArrearsSentence = strArrears & rst!Arrears & strArrearsEnd
.Bookmarks("Arrears").Range _
.InsertBefore strArrears
End If

.Bookmarks("Factor").Range _
.InsertBefore rst!Factor

.Printout

'Reset the bookmarks
.Bookmarks("MailAddress").Range _
.InsertBefore ""

.Bookmarks("TotalAmount").Range _
.InsertBefore ""

.Bookmarks("CurrentAnnualAmount").Range _
.InsertBefore ""

.Bookmarks("Description").Range _
.InsertBefore ""

.Bookmarks("bkDate").Range _
.InsertBefore ""

End With

rst.MoveNext
 
H

Helmut Weber

Hi,
How can I clear the contents of a bookmark without removing the actual
bookmark.
strictly speaking, not at all. The easiest way would be, IMHO,
to use placeholders, so called open bookmarks, like [MailAddress].
Then:
Dim oRng As Range
Set oRng = ActiveDocument.Bookmarks("MailAddress").Range
oRng.Text = "the new MailAddress" ' Bookmark has gone
' restore bookmark
ActiveDocument.Bookmarks.Add Name:="MailAddress", Range:=oRng
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
D

Dingbat

Thanks - that worked a treat!

Helmut Weber said:
Hi,
How can I clear the contents of a bookmark without removing the actual
bookmark.
strictly speaking, not at all. The easiest way would be, IMHO,
to use placeholders, so called open bookmarks, like [MailAddress].
Then:
Dim oRng As Range
Set oRng = ActiveDocument.Bookmarks("MailAddress").Range
oRng.Text = "the new MailAddress" ' Bookmark has gone
' restore bookmark
ActiveDocument.Bookmarks.Add Name:="MailAddress", Range:=oRng
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top