PDA

View Full Version : Solved: Automated chapter numbers



eed
02-21-2006, 12:17 PM
Hi, all,

I'm automating the creation of a document with sections, e.g., 1.0, 1.1, 2.0, and so forth. My code inserts chapter-page numbers at the bottom of each page, e.g., 1-1. I am currently writing code to build appendixes into the document, and I want the appendix page numbers to start with the appendix letter, e.g., A-1. But it seems as though I cannot define multiple chapter number styles in one document. When I try to define new chapter numbers in a new section, I get a runtime error that a property setting conflicts with an existing property setting. Is there something I'm missing that WILL allow me to define different chapter number styles for different document sections?

Alternately, I would be willing to just "manually" insert "A-" before the page number on each page, instead of having it formatted as a chapter number. But, once I have inserted page numbers in the footer, I'm unsure how to use my code to insert additional text in the correct place relative to the page number. Any explanation for what VBA code I would use to enter the prefixing text at the correct position in the footer?

I'm open to other method suggestions as well if anyone has any...

Thanks!! This automated document would be the death of me if it weren't for all the wonderful assistance I've been getting here. http://vbaexpress.com/forum/images/smilies/023.gif

~ eed

fumei
02-22-2006, 10:45 PM
Need some clarification.
I'm automating the creation of a document with sections, e.g., 1.0, 1.1, 2.0, and so forth. My code inserts chapter-page numbers at the bottom of each page, e.g., 1-1.1. Are these real sections, that is, are they delineated by Section Breaks?

2. Please explain Section 1.0 vs 1.1. Can section 1.0 have, say 10 pages...so would the numbering be 1.0 1, 1.0 2, 1.0 3. And 1.1 1, 1.1 2. I am confused.

3. Are you renumbering at 1 for each section (if they are real sections)?

eed
02-23-2006, 03:15 PM
Ah, very logical clarification requests.

Let's see. The numbers such as 1.0, 1.1, etc. are like outline levels. So, you'd have:
1.0
1.1
1.1.1
1.2
2.0
... and so forth. There is a next page section break before each new Outline Level 1 number. So for instance anything starting with a 1. is in a section, then there's a break and 2. starts on the next page in a new section. Each Outline Level 1 number is in Heading 1 style and is providing the chapter number which is paired with the page number in the footer.
The 1.1, 1.2, etc. entries are Outline Level 2 and in Heading 2 style. A 1.1.1 entry would be Outline Level 3 and Heading 3 style.

So, for all outline levels starting with a 1, the pages are numbered 1-1, for chapter 1, page 1. When you get to 2.0, the pages are numbered 2-1, for chapter 2, page 1. The page numbering starts over at 1 each time you reach an Outline Level 1 entry.

When an appendix starts, it is also a new section in the document. Ideally, the pages in Appendix A are numbered as A-1, A-2, etc. But I can't figure out how to write the code so that this happens correctly... the chapter numbers either end up numerical (instead of alphabetical) like the preceding document, or else I get an error message saying that I can't reset the properties related to the chapter numbers in the page numbering.

I'm getting myself confused trying to find the right terms to clarify this. If what I have said is not clear, please let me know, and I'll try to post a sample file to demonstrate what I've done so far and what I'm trying to achieve.

Thanks!!! :bow:
eed

fumei
02-27-2006, 09:39 AM
Huh?
the chapter numbers either end up numerical (instead of alphabetical) like the preceding documentWhat does THAT mean. The "chapter numbers end up numerical" - which gosh makes sense as they ARE numerical......

but what is "the preceding document". WHAT preceding document?????


Yes, you had better post a sample file.

eed
03-01-2006, 09:10 AM
Huh?What does THAT mean. The "chapter numbers end up numerical" - which gosh makes sense as they ARE numerical......

but what is "the preceding document". WHAT preceding document?????


Yes, you had better post a sample file. By numerical, I meant, even if I try to define the appendixes' chapter numbers using a list template for an alphabetical outline-style list, it just continues using the numbers from the earlier chapters of the document and will not switch to alphabetical chapter designators.

By preceding document, I meant the preceding chapters of the document.

I can't post my entire project, but I will create a trimmed-down sample file and post it later this afternoon to illustrate the problem. Thanks! =)

~ eed

eed
03-01-2006, 08:17 PM
Okay, I have attached a zip file containing an abridged sample database and the Word template that my procedure is using.

When the database and form open, use the button that says "click here to create document" to generate the document. There will be a number of blank pages at the front and back of the document; this is because I deleted (for purposes of this sample) the irrelevant code which inserts additional material into those pages. The relevant code module in the database is called basCreateDMP. The file was created in Access 2003 and contains a reference to Word 2003.

I inherited a lot of the foundational aspects of this database (like the stupidly named forms with the hyphens in them!), so I am not free to change that kind of thing at this time. I also inherited some of the Word code, and my own skills in what I've added are mediocre, so a lot of it may be sloppy even if working correctly; I apologize for that in advance!

I look forward to any suggestions you may have for formatting "A-1" style page numbers in the document appendixes... Part of my problem is that I wouldn't mind just inserting the letter manually, but when I do this, it always seems to go into the footer BEFORE the page I intended, and I don't understand why. Please post any other clarification questions that might come up, since, as I said, I know some of the code may be way less than perfect... :(

~ eed

fumei
03-03-2006, 05:29 PM
OK, I am looking at it. I had to change the References in the database - as it was using the Word 11.0 library....and I am using Word 2002, which uses Word 10.0 library. That is to say...your code failed.

eed
03-03-2006, 06:17 PM
OK, I am looking at it. I had to change the References in the database - as it was using the Word 11.0 library....and I am using Word 2002, which uses Word 10.0 library. That is to say...your code failed.
I'm sorry you found that to be a failure. This tool is only used by ten people, and all of them use the same version of Office, so it has never been a priority to deal with the references any differently. This is why I mentioned, when I posted the sample, that it was written in Access 2003 and contained a reference to Word 2003.

~ eed

eed
03-21-2006, 10:48 AM
I've finally devised a (somewhat annoying but functional) work-around for this problem, so I consider this thread solved... unfortunately my "thread tools" menu no longer seems to contain a "Mark Thread Solved" command, so I don't know how to mark this solved??
Thanks!
~ eed

mdmackillop
03-21-2006, 11:14 AM
Hi eed,
Marked solved.
Can you post your solution, It may be useful for others who find their way here.
Regards
MD

eed
03-22-2006, 04:39 PM
Hi eed,
Marked solved.
Can you post your solution, It may be useful for others who find their way here.
Regards
MD
Thanks, MD. I won't try to post the code because it's a bit convoluted and highly specific to my tool... But I'll try to describe what I did...

I had been trying to just edit the text in the current section footer while I was creating each appendix's title page. However, this always resulted in my code editing the footer for the section/page BEFORE the page I was on. That very likely was due to some part of my own stupidity, but I couldn't overcome it, whatever it was.

So I basically wrote a little procedure that runs after all the appendixes have been added to the document (with just numerical page numbers and no appendix letters added yet, no "A-"). The procedure determines how many total sections are in the document and which section begins the appendixes. That way I know with which section numbers to start and end, and I can do a loop. I explicitly GoTo the footer of each appendix's section and manually add the appendix letter and hyphen before the page number. This explicit GoTo works a lot better for me than just trying to go to the "current" footer while I'm on a page.

I have a distinct Table of Contents field which lists all the appendixes. So I also run a loop in which I explicitly GoTo that Table of Contents field and walk through each line, adding a letter and hyphen before the last character on the line (the page number; it's always one digit because every appendix's pages are numbered starting at 1). This loop runs until after I have entered the last appendix letter (which was written into a variable earlier in the document creation process).

It's not as clean as I would prefer, but it works. It has been running consistently with no errors, and it doesn't add more than a second or two to the running time of the overall process. So, it is not the ideal solution, but given the current context in which I am working, it is all I really need! :blush

~ eed