Full Version: access to word bookmarks
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Ok.. I think i have pounded my head on the desk enough smile.gif.

Here is the issue. I have a word document that I am setting up as a template. Simple merge of data but however it's always only 1 record so I am thinking a mailmerge is not really necessary since it only has one record / form infomration to put into the document.

So I setup a template in word 2007 and called it prop2.dotx. In this document I put a bookmark named : "Estimate". I will have other bookmarks but figured I'd get one to work first

on the main form I have a button that is going to populate these bookmarks. Access launches word and then i get a error: Obect variable or with block not set. HELP smile.gif.


Here is the code:

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim dbPath As String

dbPath = CurrentProject.Path & "\"

Set objWord = CreateObject("Word.Application")

With objWord
.Visible = True
Set objWordDoc = .Documents.Open(dbPath & "prop2.dotx")

With objDoc
.Bookmarks("Estimate").Range.Text = Me.EstimateID.Value
End With

End With
Which line of code errored out?
the line that errord out was .bookmarks("Estimate") line

but i did figure out the issue
Perhaps, you should post what was the cause and your solution so that others who have similar problems can find your solution.

Personally, I only used InsertBefore or InsertAfter methods of the Range object so I am not sure what your solution was.
Sorry took me awhile to get back here.

Here is the solution-

Dim wrdApp As Object
Dim wrdDoc As Object

Set wrdApp = CreateObject("Word.application")
Set wrdDoc = wrdApp.Documents.Add(dbpath & "proposal.dotx")

With wrdDoc
.Bookmarks("Estimate").Range.Text = Forms!Main!EstimateID
.Bookmarks("CurrentYear").Range.Text = Year(Now())
.Bookmarks("EstDate").Range.Text = myset!edate
.Bookmarks("Company").Range.Text = Forms!Main!CompanyID.Column(1)
.Bookmarks("address").Range.Text = maddress
.Bookmarks("city").Range.Text = mcity
.Bookmarks("state").Range.Text = mstate
.Bookmarks("zip").Range.Text = mzip
.Bookmarks("Reference").Range.Text = Forms!Main![Project Description]
.Bookmarks("lastname").Range.Text = myset!lastname
.Bookmarks("user").Range.Text = userinfo
.Bookmarks("usertitle").Range.Text = usertitle
.SaveAs sfilename, 0
End With

wrdApp.Visible = True
Thanks for posting back your solution.

It looks to me the problem was the Control/Field reference and not Word Bookmark?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.