Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-13-2020, 08:07 AM
ajgarrison ajgarrison is offline Page numbering from Access Windows 10 Page numbering from Access Office 2013
Novice
Page numbering from Access
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 10-13-2020, 08:26 AM
Charles Kenyon Charles Kenyon is offline Page numbering from Access Windows 10 Page numbering from Access Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #3  
Old 10-13-2020, 10:23 AM
ajgarrison ajgarrison is offline Page numbering from Access Windows 10 Page numbering from Access Office 2013
Novice
Page numbering from Access
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

This is a controlled document. I need to do this without user interface.
Reply With Quote
  #4  
Old 10-13-2020, 03:33 PM
Guessed's Avatar
Guessed Guessed is offline Page numbering from Access Windows 10 Page numbering from Access Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 10-13-2020, 05:30 PM
ajgarrison ajgarrison is offline Page numbering from Access Windows 10 Page numbering from Access Office 2013
Novice
Page numbering from Access
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 10-13-2020, 07:19 PM
Guessed's Avatar
Guessed Guessed is offline Page numbering from Access Windows 10 Page numbering from Access Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #7  
Old 10-14-2020, 05:58 AM
ajgarrison ajgarrison is offline Page numbering from Access Windows 10 Page numbering from Access Office 2013
Novice
Page numbering from Access
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

Good to know. I will be working with this idea today. Thank you.
Reply With Quote
  #8  
Old 10-14-2020, 08:33 AM
ajgarrison ajgarrison is offline Page numbering from Access Windows 10 Page numbering from Access Office 2013
Novice
Page numbering from Access
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 10-14-2020, 10:53 AM
Charles Kenyon Charles Kenyon is offline Page numbering from Access Windows 10 Page numbering from Access Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by ajgarrison View Post
This is a controlled document. I need to do this without user interface.

You can do this in vba.
Reply With Quote
  #10  
Old 10-14-2020, 10:54 AM
Charles Kenyon Charles Kenyon is offline Page numbering from Access Windows 10 Page numbering from Access Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You should be using

Code:
Documents.Add
rather than opening a template.
Reply With Quote
  #11  
Old 10-14-2020, 02:44 PM
Guessed's Avatar
Guessed Guessed is offline Page numbering from Access Windows 10 Page numbering from Access Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #12  
Old 10-16-2020, 10:20 AM
ajgarrison ajgarrison is offline Page numbering from Access Windows 10 Page numbering from Access Office 2013
Novice
Page numbering from Access
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

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.
Reply With Quote
  #13  
Old 10-16-2020, 05:06 PM
Guessed's Avatar
Guessed Guessed is offline Page numbering from Access Windows 10 Page numbering from Access Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #14  
Old 10-19-2020, 05:20 PM
ajgarrison ajgarrison is offline Page numbering from Access Windows 10 Page numbering from Access Office 2013
Novice
Page numbering from Access
 
Join Date: Sep 2020
Posts: 14
ajgarrison is on a distinguished road
Default

Thank you all. The problem was not my code, it was the Word document formatting.
I do appreciate all the help.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page numbering from Access Page-numbering question: continue numbering from one section to the next? {PAGE} of {SECTIONPAGES} SDwriter Word 12 10-25-2017 06:56 AM
Page numbering from Access How to add page numbering after next page break with landscape and portrait Jashley1 Word 2 11-25-2014 10:36 PM
Page numbering from Access begin each section with page 1 in header PLUS continuous page numbering in footer onemorecupofcoffee Word 18 09-04-2013 04:31 PM
Page numbering from Access 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft