Mar 30 2009, 01:53 PM
Ok.. I think i have pounded my head on the desk enough <.
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 <.
THere 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")
.Visible = True
Set objWordDoc = .Documents.Open(dbPath & "prop2.dotx")
.Bookmarks("Estimate").Range.Text = Me.EstimateID.Value
Mar 30 2009, 04:59 PM
Which line of code errored out?
Mar 31 2009, 07:59 AM
the line that errord out was .bookmarks("Estimate") line
But i did figure out the issue
Mar 31 2009, 05:46 PM
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.
Apr 15 2009, 07:37 AM
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")
.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
wrdApp.Visible = True
Apr 15 2009, 08:17 AM
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 UA. To view the full version with more information, formatting and images, please click here