Consulting

Results 1 to 7 of 7

Thread: Solved: Word document generation page question

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location

    Solved: Word document generation page question

    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
    Mike

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Could you not just use Mail Merge from Word with Access as the data source?

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Quote Originally Posted by Norie
    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
    Mike

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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
    K :-)

  5. #5
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    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.

  6. #6
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Actually im not going to do this. I realized this little detail is nothing.

  7. #7
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Fair enough, although it's all in the detail (or, if you're a lawyer, the small print)
    K :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •