Using Bookmarks in Word from MS Access

E

Elaine

From an MS Access Database I am using bookmarks to replace text in a Word
document with text from a database field. I have 12 bookmarks that include 4
which are named POC, BusinessName, Address1 and Address2. All of the
bookmarks except these 4 are working properly in that the text is being
replaced with the information from the database. I have deleted them and
reinserted the bookmarks. I have also renamed them but these 4 don't replace
the text. I know there is information in the field, so it's not a blank
field that's causing the problem. I have several letters that need to be
automated and each one is experience the same problem with fields with these
names and I can't figure out what I'm doing wrong. Can anyone help me with
this. I'm using Office 2007 and below is the code I'm using.

With objDoc
.Bookmarks("dDate").Range.Text = Format(rst.Fields("dDate"),
"mmmm dd, yyyy")
.Bookmarks("POC").Range.Text = Nz(rst.Fields("POC"))
.Bookmarks("BusinessName").Range.Text =
Nz(rst.Fields("BusinessName"))
.Bookmarks("Address1").Range.Text = Nz(rst.Fields("Address1"))
.Bookmarks("Address2").Range.Text = Nz(rst.Fields("Address2"))
.Bookmarks("C").Range.Text = Nz(rst.Fields("C"))
.Bookmarks("BondID").Range.Text = Nz(rst.Fields("BondID"))
.Bookmarks("Acct").Range.Text = Nz(rst.Fields("Account"))
.Bookmarks("InsCO").Range.Text = Nz(rst.Fields("InsuranceCo"))
.Bookmarks("DepReq").Range.Text =
Format(Nz(rst.Fields("DepRequired")), "$#,#00.00")
.Bookmarks("DteDue").Range.Text = Nz(rst.Fields("DteDue"))
.Bookmarks("ExpDate").Range.Text = Nz(rst.Fields("ExpDate"))
End With
 
D

Doug Robbins - Word MVP

While it may not hurt, the should be no need for the Nz() function in that
situation.

What do you see if you include a command like

MsgBox rst.Fields("POC")

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

Elaine

I tried your suggestions. I do have data there, but it's not going to those
particular bookmarks. Any other suggestions? As for the Nz() function, for
this situation, I found that it worked smoother. I guess it's just a
personal preference on my part. Thanks for your help.
 
D

Doug Robbins - Word MVP

What do you get if you replace

.Bookmarks("POC").Range.Text = Nz(rst.Fields("POC"))

by

.Bookmarks("POC").Range.Text = "This is a test" 'Nz(rst.Fields("POC"))

Does the text "This is a test" get inserted into that bookmark?


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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