Hi Joe,
> What I have is a Lease done in Word XP with about 30 bookmarks in the body
> of the form. This all works perfectly from my Access XP application. Now a
[quoted text clipped - 5 lines]
> print fine again. Is there some trick or technique to using bookmarks in the
> header with Word 2002/XP.
You don't really give us enough information to go on (such as, the code you're
using).
However, I can suggest another approach that doesn't use bookmarks, and will
avoid addressing the header/footer region directly in your code. Create a
document Variable (look up VARIABLE in Word's VBA help) and put the information
into that. Insert in the header a DocVariable field (Insert/Fields) that
references this variable.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
Joe Cilinceon - 28 Nov 2005 15:53 GMT
Cindy M -WordMVP- wrote:
> Hi Joe,
> You don't really give us enough information to go on (such as, the
> code you're using).
[quoted text clipped - 6 lines]
>
> Cindy Meister
Thanks for responding Cindy and I don't think the Access code has much to do
with this as it works for the 27 other bookmarks in the document. I did
include a scaled down version of it below. The only bookmark affecting it is
the header bookmark. If I take it out, no problem put it back and it will
print the first time then I need to close the Access app and restart it to
print another copy. I did look at the Microsoft KB for this and found a
macro work around that just didn't work with my version (is was for a 2000
version, I'm using 2002). I will check out the document variable approch
and see if that works. I will still have to pass the data from Access to
Word.
Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
'Start Microsoft Word.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open (Application.CurrentProject.path &
"\Lease\Lease.doc")
'Move to each bookmark and insert text from the form.
The next 2 lines are to the header
'ActiveDocument.Bookmarks("lease").Select
'.Selection.Text = ([fsubTenantLeases].Form![LedgerID])
I have remove some of these to just save some space as it really doesn't
matter how many as these are all in the body and work fine.
.ActiveDocument.Bookmarks("ax1").Select
.Selection.Text = (CStr(FORMS![frmTENANTS]![AccountName]))
.ActiveDocument.Bookmarks("ax2").Select
.Selection.Text =
(CStr(Trim(FORMS![frmTENANTS]![fsubTenantAddress].Form![Address1])))
.ActiveDocument.Bookmarks("ax3").Select
.Selection.Text =
(CStr(Trim(FORMS![frmTENANTS]![fsubTenantAddress].Form![Address2])))
. End With
'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
objWord.ActiveDocument.PrintOut Background:=False
'Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Quit Microsoft Word and release the object variable.
objWord.Quit
Set objWord = Nothing
Exit Sub
MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub

Signature
Joe Cilinceon
Cindy M -WordMVP- - 29 Nov 2005 13:33 GMT
Hi Joe,
> I don't think the Access code has much to do
> with this
Yes, as a matter of fact it does. You're doing what I
suspected - trying to jump to the bookmarks, rather than
manipulate the objects. And that simply doesn't work well
with headers and footers.
'ActiveDocument.Bookmarks("lease").Select
'.Selection.Text =
([fsubTenantLeases].Form![LedgerID])
Do this, instead:
Dim doc as word.Document
Set doc =
.Documents.Open(Application.CurrentProject.path _
& "\Lease\Lease.doc")
doc.Bookmarks("lease").Range.Text = _
([fsubTenantLeases].Form![LedgerID])
You'll find it's also rather faster and easier on the
users' eyes :-)
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)
Joe Cilinceon - 29 Nov 2005 13:53 GMT
Thanks again Cindy I'll give it a try. I'm also messing with Ref for a few
of these. Some of the stuff at the top of the document, such as Rent, Late
Fee, Adm. Fee charges and such repeat in the last paragraph of the document.
I'm trying to get Ref bookmark's name to work but so far all I get is an
error in my paragraph. All of this is just to fine tune a working
application.
Oh and the header/footer I fixed with the macro from MS in the Word document
itself. This is the only document created in real time from an open set of
Access forms. We print at the time we rent a storage unit.
--
Joe Cilinceon
Cindy M -WordMVP- wrote:
> Hi Joe,
>
[quoted text clipped - 31 lines]
> follow question or reply in the newsgroup and not by e-mail
> :-)