Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Bookmarks in Header/Footer
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. -- Joe Cilinceon |
#2
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Bookmarks in Header/Footer
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 :-) |
#3
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Bookmarks in Header/Footer
Cindy M -WordMVP- wrote:
Hi Joe, 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 -- Joe Cilinceon |
#4
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Bookmarks in Header/Footer
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 :-) |
#5
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Bookmarks in Header/Footer
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, 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 :-) |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
troubleshooting hyperlink bookmarks | Page Layout | |||
First page header/footer appearing on second page as well! | Page Layout | |||
Inserting letter text causes header/footer to disappear | Page Layout | |||
Bookmarks appearing in HTML Format document links | Microsoft Word Help | |||
Add bookmarks in header/footer | Microsoft Word Help |