UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> access to word bookmarks    
 
   
Keaian
post Mar 30 2009, 01:53 PM
Post #1

UtterAccess Veteran
Posts: 323



Ok.. I think i have pounded my head on the desk enough (IMG:style_emoticons/default/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 (IMG:style_emoticons/default/smile.gif) .

TIA

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
Go to the top of the page
 
+
 
Start new topic
Replies (1 - 5)
vtd
post Mar 30 2009, 04:59 PM
Post #2

Retired Moderator
Posts: 19,667



Which line of code errored out?
Go to the top of the page
 
+
Keaian
post Mar 31 2009, 07:59 AM
Post #3

UtterAccess Veteran
Posts: 323



the line that errord out was .bookmarks("Estimate") line

but i did figure out the issue
Go to the top of the page
 
+
vtd
post Mar 31 2009, 05:46 PM
Post #4

Retired Moderator
Posts: 19,667



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.
Go to the top of the page
 
+
Keaian
post Apr 15 2009, 07:37 AM
Post #5

UtterAccess Veteran
Posts: 323



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
'.MoveFirst
.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
Go to the top of the page
 
+
vtd
post Apr 15 2009, 08:17 AM
Post #6

Retired Moderator
Posts: 19,667



Thanks for posting back your solution.

It looks to me the problem was the Control/Field reference and not Word Bookmark?
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 25th May 2013 - 04:36 AM