OK, I think this is my last question (man I hope....anyway), reading the VBA
help files, I have found the insertbreak type=wdPageBreak, and have tried
tying it to a new section, but what happens in my original page just gets
overwritten,so where I should have 12 pages, I have 1, the data is changing
correctly, but the new page isn't there....I can't find a simple AddNewPage,
and I'm a tad confused by the sections() vs range stuff.....

Thank you

Re: Section Break and a New Page by Bernhard

Bernhard
Sun Feb 12 09:04:08 CST 2006

Hi Pastor Hank,

> OK, I think this is my last question (man I hope....anyway), reading the VBA
> help files, I have found the insertbreak type=wdPageBreak, and have tried
> tying it to a new section, but what happens in my original page just gets
> overwritten,so where I should have 12 pages, I have 1, the data is changing
> correctly, but the new page isn't there....I can't find a simple AddNewPage,
> and I'm a tad confused by the sections() vs range stuff.....
a nice way to find out what and how to do: go to word and record a macro with
the steps you need. Then have a look at the recorded macro. Often you can
translate the macro 1:1 to foxpro.

A section is part of the document hierarchy:
a Document is at top level. It contains one or more section. There is at least
one section in a document.
A section is at second level. It contains one or more paragraphs. Again there is
at least on paragraph in a section.
A paragraph contains text and other objects.

A range is an object you can use in macros (or from foxpro). A range can contain
a large or a small part of a document. It is something like a invisible
"selection".
But don't mix it up with the object "selection". This is a selected part of your
document, you can see the selection in the document window of word. You can have
not more than one selection object at a time, whereas you can have different
range objects.

HTH
Regards
Bernhard Sander

Re: Section Break and a New Page by PastorHank

PastorHank
Sun Feb 12 17:09:27 CST 2006

Hi Bernard,

Here's what's happening. I ran a macro and manually inserted a new page and
got this code (modified from the VBA version)

oRange.MoveEnd( wdStory)
oRange.Collapse( wdCollapseEnd )
With oRange
.Collapse Direction = wdCollapseEnd
.InsertBreak Type=wdPageBreak
EndWith
This is right before where the program loops back to a Do While !eof()
statement that is processing the data

Now what's happening is that the document is rewriting the first page.
Things return to the top of the page, and the page fills in with the next set
of data, but instead of having 12 pages (one for each master record) I have 1
page, with the page showing only. It's just returning to the top of the
previous or last page. The page has 4 tables on it, do I need to renumber
the tables each time?, I've tried incrementing the sections[], to no avail....

Hank



"Bernhard Sander" wrote:

> Hi Pastor Hank,
>
> > OK, I think this is my last question (man I hope....anyway), reading the VBA
> > help files, I have found the insertbreak type=wdPageBreak, and have tried
> > tying it to a new section, but what happens in my original page just gets
> > overwritten,so where I should have 12 pages, I have 1, the data is changing
> > correctly, but the new page isn't there....I can't find a simple AddNewPage,
> > and I'm a tad confused by the sections() vs range stuff.....
> a nice way to find out what and how to do: go to word and record a macro with
> the steps you need. Then have a look at the recorded macro. Often you can
> translate the macro 1:1 to foxpro.
>
> A section is part of the document hierarchy:
> a Document is at top level. It contains one or more section. There is at least
> one section in a document.
> A section is at second level. It contains one or more paragraphs. Again there is
> at least on paragraph in a section.
> A paragraph contains text and other objects.
>
> A range is an object you can use in macros (or from foxpro). A range can contain
> a large or a small part of a document. It is something like a invisible
> "selection".
> But don't mix it up with the object "selection". This is a selected part of your
> document, you can see the selection in the document window of word. You can have
> not more than one selection object at a time, whereas you can have different
> range objects.
>
> HTH
> Regards
> Bernhard Sander
>

Re: Section Break and a New Page by Bernhard

Bernhard
Sun Feb 12 19:28:23 CST 2006

Hi Hank

> oRange.MoveEnd( wdStory)
> oRange.Collapse( wdCollapseEnd )
> With oRange
> .Collapse Direction = wdCollapseEnd
> .InsertBreak Type=wdPageBreak
> EndWith
> This is right before where the program loops back to a Do While !eof()
> statement that is processing the data
>
> Now what's happening is that the document is rewriting the first page.
> Things return to the top of the page, and the page fills in with the next set
> of data, but instead of having 12 pages (one for each master record) I have 1
> page, with the page showing only. It's just returning to the top of the
> previous or last page. The page has 4 tables on it, do I need to renumber
> the tables each time?, I've tried incrementing the sections[], to no avail....

The above code doesn't look bad. (Only: one collapse would be enough)
It seems to me as if at the beginning of your DO WHILE loop you delete quiet a
lot of stuff from the document, maybe you simply replace the text of a range or
selection instead of inserting before or after.

Why do you want to have more than one section? This would only be necessary, if
you want different margins or different headers/footers or things like that.

Regards
Bernhard Sander

Re: Section Break and a New Page by PastorHank

PastorHank
Sun Feb 12 19:39:07 CST 2006

Bernhard,

I need to be able to print one master record with related child data (that
comes from 3 other files - the child data all needs to be in seperate tables
(client request) )per page....Since my master file is a limited file (the
current run only has 12 records) for now (and to meet a deadline) I have made
a form that allows them to select which one to print....that way I can study
more of the 'insertbreak' commands and learn more about VBA....

I do appreciate your help, it's been pointing me in the right direction...as
far as different sections, I dropped that code, I just want new pages...

Hank

"Bernhard Sander" wrote:

> Hi Hank
>
> > oRange.MoveEnd( wdStory)
> > oRange.Collapse( wdCollapseEnd )
> > With oRange
> > .Collapse Direction = wdCollapseEnd
> > .InsertBreak Type=wdPageBreak
> > EndWith
> > This is right before where the program loops back to a Do While !eof()
> > statement that is processing the data
> >
> > Now what's happening is that the document is rewriting the first page.
> > Things return to the top of the page, and the page fills in with the next set
> > of data, but instead of having 12 pages (one for each master record) I have 1
> > page, with the page showing only. It's just returning to the top of the
> > previous or last page. The page has 4 tables on it, do I need to renumber
> > the tables each time?, I've tried incrementing the sections[], to no avail....
>
> The above code doesn't look bad. (Only: one collapse would be enough)
> It seems to me as if at the beginning of your DO WHILE loop you delete quiet a
> lot of stuff from the document, maybe you simply replace the text of a range or
> selection instead of inserting before or after.
>
> Why do you want to have more than one section? This would only be necessary, if
> you want different margins or different headers/footers or things like that.
>
> Regards
> Bernhard Sander
>

Re: Section Break and a New Page by Olaf

Olaf
Mon Feb 13 03:45:20 CST 2006

Hi Pastor,

it may help to post your full loop. Maybe you have somthing stupid as
oWord.AddDocument at the begin of each loop, therefore ending up
with 12 documents, or even creating 12 instances of word, and after
processing making only the last one visible.

Bye, Olaf.



Re: Section Break and a New Page by PastorHank

PastorHank
Mon Feb 13 07:04:27 CST 2006

Olaf,
I'd prefer not to be called 'stupid', inexperienced yes, 'stupid' no. And
no the activation of word is outside the loop and so is the creation of the
document. The only things inside the loop are the creation of a title and
the data. And the title is not a page header.


"Olaf Doschke" wrote:

> Hi Pastor,
>
> it may help to post your full loop. Maybe you have somthing stupid as
> oWord.AddDocument at the begin of each loop, therefore ending up
> with 12 documents, or even creating 12 instances of word, and after
> processing making only the last one visible.
>
> Bye, Olaf.
>
>
>

Re: Section Break and a New Page by Fred

Fred
Mon Feb 13 08:57:04 CST 2006

I don't think Olaf was calling you "stupid". I do some really dumb things
in my code quite frequently, and it usually takes someone else pointing it
out to make it quite obvious. <s>

It's a bit hard to determine just what needs to be done from a newsgroup
posting, Olaf was just trying to gather more information.

--
Fred
Microsoft Visual FoxPro MVP


"Pastor Hank" <PastorHank@discussions.microsoft.com> wrote in message
news:E4CC84FF-E22A-4AED-B1B9-1670CE3946CC@microsoft.com...
> Olaf,
> I'd prefer not to be called 'stupid', inexperienced yes, 'stupid' no. And
> no the activation of word is outside the loop and so is the creation of
> the
> document. The only things inside the loop are the creation of a title and
> the data. And the title is not a page header.
>
>
> "Olaf Doschke" wrote:
>
>> Hi Pastor,
>>
>> it may help to post your full loop. Maybe you have somthing stupid as
>> oWord.AddDocument at the begin of each loop, therefore ending up
>> with 12 documents, or even creating 12 instances of word, and after
>> processing making only the last one visible.
>>
>> Bye, Olaf.
>>
>>
>>



Re: Section Break and a New Page by PastorHank

PastorHank
Mon Feb 13 09:11:30 CST 2006

Ah, after multiple hours of looking and reading and retyping and getting
frustrated again and again one tends to be fragile....

So - my code to start everything (after the Define statements)
oWord = CREATEOBJECT("Word.Application")
oWord.visible = .t.
oDoc = oWord.Documents.Add()
***Page Setup

WITH oDoc.PageSetup
.BottomMargin = 0.50 * autoInchesToPoints
.TopMargin = 0.50 * autoInchesToPoints
.LeftMargin = 0.50 * autoInchesToPoints
.RightMargin = 0.50 * autoInchesToPoints
.DifferentFirstPageHeaderFooter = .T.
.OddAndEvenPagesHeaderFooter = .t.
ENDWITH

oHeaderStyle = oDoc.Styles.Add("CenterHeader",wdStyleTypeParagraph)
WITH oHeaderStyle
.ParagraphFormat.Alignment = wdAlignParagraphCenter
ENDWITH
Then I gather my anchor tables
Then I start my DO WHILE !EOF()

The only code outside of adding tables is
cDate=DTOC(DATE())
cTitle1 = "Name Changed to Protect Client"
cTitle2 = "Breeding Program"
cTitle3 = "Doe"
cTitle =
cTitle1+CHR(13)+cTitle2+CHR(13)+CHR(13)+cTitle3+CHR(13)+ALLTRIM(lcDoeToFind)

oRange = oDoc.Range()
WITH oRange
.Text = (cTitle)
.Style = oHeaderStyle
.FONT.BOLD = .T.
.InsertAfter(CR)
ENDWITH
*
Then
oRange = oDoc.Range()
oRange.MoveEnd( wdStory)
oRange.Collapse( wdCollapseEnd )

And from that point on it is building tables etc.
Everything seems to be in the correct place...
I've looked at the InsertBreak and it has a constant of wdPageBreak which I
cannot for the life of me find out what the value of it is in case it's just
being ignored.

Hank


"Fred Taylor" wrote:

> I don't think Olaf was calling you "stupid". I do some really dumb things
> in my code quite frequently, and it usually takes someone else pointing it
> out to make it quite obvious. <s>
>
> It's a bit hard to determine just what needs to be done from a newsgroup
> posting, Olaf was just trying to gather more information.
>
> --
> Fred
> Microsoft Visual FoxPro MVP
>
>
> "Pastor Hank" <PastorHank@discussions.microsoft.com> wrote in message
> news:E4CC84FF-E22A-4AED-B1B9-1670CE3946CC@microsoft.com...
> > Olaf,
> > I'd prefer not to be called 'stupid', inexperienced yes, 'stupid' no. And
> > no the activation of word is outside the loop and so is the creation of
> > the
> > document. The only things inside the loop are the creation of a title and
> > the data. And the title is not a page header.
> >
> >
> > "Olaf Doschke" wrote:
> >
> >> Hi Pastor,
> >>
> >> it may help to post your full loop. Maybe you have somthing stupid as
> >> oWord.AddDocument at the begin of each loop, therefore ending up
> >> with 12 documents, or even creating 12 instances of word, and after
> >> processing making only the last one visible.
> >>
> >> Bye, Olaf.
> >>
> >>
> >>
>
>
>

Re: Section Break and a New Page by Bernhard

Bernhard
Mon Feb 13 09:35:23 CST 2006

Hi Hank,

> oRange = oDoc.Range()
> WITH oRange
> .Text = (cTitle)
> .Style = oHeaderStyle
> .FONT.BOLD = .T.
> .InsertAfter(CR)
> ENDWITH
I think, this is the point. oDoc.Range().Text is the whole Text of your
document. Now you are replacing oRange.Text with other text instead of appending
the text to the end of the range.
Try oRange.InsertAfter(cTitle) instead of .oRange.Text = cTitle

Regards

Bernhard Sander


Re: Section Break and a New Page by Olaf

Olaf
Mon Feb 13 09:33:01 CST 2006

Hi Pastor,

sorry, I was really talking about code when
writing "somthing stupid". Even made some stupid
typo myself :-) Nobody's perfect.

> oRange = oDoc.Range()
> WITH oRange
> .Text = (cTitle)

This is inside the loop, did I understand you
correctly? As that comes after you wrote:
>Then I gather my anchor tables
>Then I start my DO WHILE !EOF()

I'd say with That oDoc as selected Range
you'd overwrite the whole "story" (wdStory)
you've got so far with the title.

Even if that may also be before looping:
As you have Word visible, why not simply
set breakpoints at certain points in your code
and see if you overwrite something in the next
step? That should find the offending code...

Bye, Olaf.




Re: Section Break and a New Page by PastorHank

PastorHank
Mon Feb 13 10:14:29 CST 2006

Thanks Bernard, that helped a lot, now it's at least giving me new pages,
things aren't quite right on pages 2-12 but it's getting closer, (that's
after I changed the text to insertafter...) so, thanks for all the help from
everybody, I'm learning a whole lot more about VBA and Automating Word then I
ever dreamed I'd need to....I need to understand more about manipulating this
Range object....

and Olaf I'm just tired and cranky and my back hurts...so I misunderstood
what you were saying....


"Olaf Doschke" wrote:

> Hi Pastor,
>
> sorry, I was really talking about code when
> writing "somthing stupid". Even made some stupid
> typo myself :-) Nobody's perfect.
>
> > oRange = oDoc.Range()
> > WITH oRange
> > .Text = (cTitle)
>
> This is inside the loop, did I understand you
> correctly? As that comes after you wrote:
> >Then I gather my anchor tables
> >Then I start my DO WHILE !EOF()
>
> I'd say with That oDoc as selected Range
> you'd overwrite the whole "story" (wdStory)
> you've got so far with the title.
>
> Even if that may also be before looping:
> As you have Word visible, why not simply
> set breakpoints at certain points in your code
> and see if you overwrite something in the next
> step? That should find the offending code...
>
> Bye, Olaf.
>
>
>
>

Re: Section Break and a New Page by Olaf

Olaf
Mon Feb 13 15:38:51 CST 2006

> and Olaf I'm just tired and cranky and my back hurts...so I misunderstood
> what you were saying....
Never mind. I'm glad I could help once more.

The way I like to do it is using the Object Collections (Paragraphs, Tables, ...):
oDoc.Tables.Add()
or
oDoc.Paragraphs.Add()
or...

Perhaps that would help finding the right (the new objects) Range.

Bye, Olaf.