Bookmarks in Header/Footer

J

Joe Cilinceon

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
problem arises when I add a book mark to the header, I'm trying to add a
lease number to the header. Well as long as the bookmark is in the main body
no problem, I call the routine as many times as I like. However with the
bookmark in the header it works the first time it is called and the second
time hangs on the header bookmark. I restart the application and it will
print fine again. Is there some trick or technique to using bookmarks in the
header with Word 2002/XP.
 
C

Cindy M -WordMVP-

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
problem arises when I add a book mark to the header, I'm trying to add a
lease number to the header. Well as long as the bookmark is in the main body
no problem, I call the routine as many times as I like. However with the
bookmark in the header it works the first time it is called and the second
time hangs on the header bookmark. I restart the application and it will
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 :)
 
J

Joe Cilinceon

Cindy said:
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

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
 
C

Cindy M -WordMVP-

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
:)
 
J

Joe Cilinceon

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

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)


This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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