#1
|
|||
|
|||
Page numbering from Access
Background: I am using MS Access to open, populate and print a Word document. The document is a long template and I only print specific pages based upon certain conditions.
My question is: how can I number the Word document as Page x of y based upon the pages I'm printing for each condition? In other words, if I print 10 of 70 pages I want the printed document to have Page 1 of 10, 2 of 10 etc. on the printed document. Thanks in advance for any help. |
#2
|
|||
|
|||
Why not temporarily copy your document, delete what you do not want, and print what is left. That way, you can use Word fields for your page x of y and use a regular footer.
Word is not very good at parsing pages, things can get unpredictable. You can make it more predictable by using Heading Styles and page-break-before formatting. |
#3
|
|||
|
|||
This is a controlled document. I need to do this without user interface.
|
#4
|
||||
|
||||
You haven't explained how you are specifying the conditions of which pages are being selected for print.
I would be looking to set the font property of content on the non-printing pages as 'Hidden' and then print the entire document.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
If x = y then
Wrd.ActiveDocument.PrintOut , Copies:=1, Range:=wdPrintRangeOfPages, Pages:="1-4,6,8,10,14-19,22-24,26" End If I started with using sections and "hiding" what would not print. I went away from this because in the middle of the document we need to print multiple copies of a page based on other criteria. I couldn't learn how to print a section multiple times, so I drifted away from that approach. If someone could point me towards printing a section multiple times I could return to that approach. Thank you so much all the help is very much appreciated. |
#6
|
||||
|
||||
Sections have a special meaning in Word which might not correspond with your intention. You can specify pages to be printed by sections as well which could give you multiple copies.
Pages:="s1-s3,s4,s4,s4,s5-s8"
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
Good to know. I will be working with this idea today. Thank you.
|
#8
|
|||
|
|||
I think I'm on the right direction now, but stuck on how to do it. From Access I open the Word template, fill in fields from Access then have a series of If/then to print certain pages. That is the end goal.
I think the approach is to open the document, fill in fields, then delete the pages I don't want printed, then print. Where I'm stuck now is deleting those pages in the document that opens. I've googled, but not seeing anything that applies/or works. Here is an example of the pages I need to delete from a 70 page document: 5,7-9,11-14,20-21,25,29,32-37,39,42,51-53,57-69 Again, thank you all for the help. I'm very appreciative. |
#9
|
|||
|
|||
Quote:
You can do this in vba. |
#10
|
|||
|
|||
You should be using
Code:
Documents.Add |
#11
|
||||
|
||||
The reason you won't find much on deleting 'pages' is because a 'page' is a slippery concept dependent on content formatting and not how Word measures content. The way you should be defining these locations is via 'fixed' ranges such as bookmarks or sections rather than by pages. If you can tag the content removal in some way it becomes much easier to work with.
I don't know what process you are using to produce the document from Access but to me it would seem to make more sense to modify that process to NOT export that content if you didn't want it in the resulting Word document. Where/when is the decision on what pages to print made?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#12
|
|||
|
|||
Here is my codeof relevant snippets) - and I think you are right on the pages because this code is giving me very strange results.
Dim Wrd As New Word.Application Set Wrd = CreateObject("Word.Application") 'Specify the path and name to the Word document. Dim MergeDoc As String MergeDoc = "S:\K Jones Only\WordMBR.docx" 'Open the document template, make it visible. Wrd.Documents.Add MergeDoc Wrd.Visible = True Dim I As Integer Dim xRange As Range Dim xPage As String Dim xArr Dim xPageCount As Long Dim xSplitCount As Long Wrd.ScreenUpdating = False If Format = "U1" Then If Left(rst.Fields("Classification"), 1) = "C" Then 'UD is a control xPage = "4,6,8,10,11,12,20,21,24,28,29,30,31,32,35,38,39,4 0,41,43,46,50,51,52,53,54,55,56,57,58,59,60,61" MsgBox "U1-Control" Else 'UD is not a controlled xPage = "4,6,8,9,10,11,12,14,20,21,24,28,29,30,31,32,35,38 ,39,40,41,43,46,50,51,52,53,54,55,56,57,58,59,60,6 1,71,72,73,74" MsgBox "U1-Not Controlled" End If End If xArr = Split(xPage, ",") xPageCount = UBound(xArr) For I = xPageCount To 0 Step -1 Wrd.Selection.GoTo wdGoToPage, wdGoToAbsolute, xArr(I) Wrd.ActiveDocument.Bookmarks("\Page").Range.Delete Next Wrd.ScreenUpdating = True The end result of this code is I'm getting pages that I have specified to delete and I'm getting 2 page 21s. So, clearly my approach is faulty. Again, thank you all for the help. |
#13
|
||||
|
||||
I can't see how you are using the access data to populate the Word docs from this code so it might be worth suggesting an alternative approach? Why not have multiple word doc templates already created and use your If section to determine which of the Word docs to open. Eg
MergeDoc = "S:\K Jones Only\WordMBR Control.docx" vs MergeDoc = "S:\K Jones Only\WordMBR Out of Control.docx"
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#14
|
|||
|
|||
Thank you all. The problem was not my code, it was the Word document formatting.
I do appreciate all the help. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Page-numbering question: continue numbering from one section to the next? {PAGE} of {SECTIONPAGES} | SDwriter | Word | 12 | 10-25-2017 06:56 AM |
How to add page numbering after next page break with landscape and portrait | Jashley1 | Word | 2 | 11-25-2014 10:36 PM |
begin each section with page 1 in header PLUS continuous page numbering in footer | onemorecupofcoffee | Word | 18 | 09-04-2013 04:31 PM |
Parallel page numbering/same page numbers for odd and even pages | goran | Word | 2 | 11-02-2012 03:42 PM |
Page Header and Page Numbering for Technical Book | SQLUSA | Word | 4 | 06-25-2012 09:53 AM |