View Full Version : Solved: Word document generation page question

04-13-2005, 08:03 AM
Hi guys,
Its me again. I appreciate all the help from this forum. It seems like finding answers to VBA questions takes forever on the internet.
Anyway, i am generating a report from access into a word document. Im writing line by line using:

ObjWord.Selection.TypeText Text:="xxxxxxx"

Im reading the information from the database. For each record that i read i have to write two lines in the word document.
So i basically do:

ObjWord.Selection.TypeText Text:="Record1FirstPart" & vbCrLf
ObjWord.Selection.TypeText Text:="Record1SecondPart" & vbCrLf
ObjWord.Selection.TypeText Text:="Record2FirstPart" & vbCrLf
ObjWord.Selection.TypeText Text:="Record2SecondPart" & vbCrLf

and so on.
The problem is that when the document goes to the next page, I do not want the first line of record one being on one page and the second part being on the second page. I was thinking about hardcoding and counting the amount of lines per page, but then i change the font size so that would be different.
Anyway have any ideas on how i can "Test" if there is enough room left on a page for the next two lines?
Or maybe someone knows a better workaround this.

Thank you very much

04-13-2005, 08:17 AM
Could you not just use Mail Merge from Word with Access as the data source?

04-13-2005, 11:10 AM
Could you not just use Mail Merge from Word with Access as the data source?

MailMerge is buggy as hell. Plus its kinda different in different versions of Word.

Also while were on the topics of reports, is there an event that executes everytime your report reads a new record??

Thank you

04-13-2005, 12:11 PM
I don't think you need to use code - just word styles in the report document.
Create two indentical styles, ReportStyle1 and ReportStyle2, set the "style for following paragraph in reverse (2 follows1, 1 follow 2) and with style 1, in it's Paragraph>Page and line breaks settings, check the "keep with next" box".
Because your output has a paragraph after each part of the output, the styles will alternate and the first style will go with the second if either go over the page

04-14-2005, 07:04 AM
Im going to do this to template that im using for this word document generation. Thank you for your help. I will let you know how it went.

04-15-2005, 07:47 AM
Actually im not going to do this. I realized this little detail is nothing.

04-15-2005, 07:51 AM
Fair enough, although it's all in the detail (or, if you're a lawyer, the small print) :)