Jay
Thu Feb 21 10:02:54 PST 2008
Grenier wrote:
> Automation a word report from Access. At run time, I want to be able
> to insert 2 field type to a company name. One type for a TOC and a
> second for an index. I'am using a table for an uniform layout. How
> can I simply insert those field right after the company name in the
> cell ? Maybe I started all wrong ?
>
> Do until rst.eof
> Set Tbl = Wrd.ActiveDocument.Tables.Add(Wrd.Selection.Range, 8, 2)
> with Tbl
> .Cell(1, 1).Range.Text = "Company name :"
> .Cell(1, 1).Range.Style = wdStyleStrong
>
> .Cell(1, 2).Range.Text = rst!CompName
> 'insert {XE "test"}{TC "Test" \l 1} after the company name...
> end with
>
> wrd.selection.InsertBreak Type:=wdSectionBreakNextPage
> rst.movenext
> loop
Dim Tbl As Table
Dim Rg As Word.Range
Do until rst.eof
Set Tbl = ActiveDocument.Tables.Add(Selection.Range, 8, 2)
With Tbl
.Cell(1, 1).Range.Text = "Company name :"
.Cell(1, 1).Range.Style = wdStyleStrong
.Cell(1, 2).Range.Text = rst!CompName
Set Rg = .Cell(1, 2).Range
Rg.MoveEnd wdCharacter, -1 ' omit cell marker from range
Rg.Collapse wdCollapseEnd
With ActiveDocument.Fields
'insert {XE "test"}{TC "Test" \l 1} after the company name...
.Add Rg, wdFieldIndexEntry, rst!CompName
Rg.Collapse wdCollapseEnd
.Add Rg, wdFieldTOCEntry, rst!CompName & " \l 1"
End With
End With
Tbl.Select
With Selection
.Move wdCharacter, 1 ' get past table marker
.InsertBreak Type:=wdSectionBreakNextPage
End With
rst.movenext
Loop
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.