Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Im using word as a report generator 2

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
Im using word as a report generator in a VB app Im writing.
I want to use word tables in the doc fiel but when I call for a second table it nests itself in the first table. Can anyoe help.

 
I setup a word doc as a template with bookmarks where I wanted the various bits of the report. Here is a snippet (names changed to protect the guilty). It doesn't show error checking or dimensioning etc. but should give a feel for it. You will note I send a concatenated string for the table data and convert within Word on the fly

Set mydoc = ActiveDocument
Set myrange = ActiveDocument.Bookmarks("jobno").Range
myrange.InsertAfter Me.cboJobs.Text
Set myrange = ActiveDocument.Bookmarks("docno").Range
myrange.InsertAfter page$
Set myrange = ActiveDocument.Bookmarks("user").Range
myrange.InsertAfter username$
mystr = mystr & "Description$Qty$Value" & vbCrLf
For temp1 = 1 To count1 - 1
mystr = mystr & Me.lvwParts.ListItems(temp1).Text & "$" & Me.lvwParts.ListItems(temp1).SubItems(1) & "$" & Me.lvwParts.ListItems(temp1).SubItems(2) & "$" & vbCrLf
Next temp1
Set myrange = mydoc.Bookmarks("list").Range
myrange.InsertAfter mystr
With myrange
.ConvertToTable Separator:="$", _
NumColumns:=5, Format:=wdTableFormatGrid7, ApplyBorders:=True _
, ApplyShading:=True, ApplyFont:=True, ApplyColor:=True, ApplyHeadingRows _
:=False, ApplyLastRow:=False, ApplyFirstColumn:=False, ApplyLastColumn:= _
False, AutoFit:=True
End With
mydoc.PrintOut

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Hi Dashley,
I've just been playing with this when I saw your question.

If you want to insert tables dynamically you need to set the range to where you want the table to be inserted.
Something like this...

Code:
    With oWordApp
    
        .Documents.Add
        .Visible = True
    'Specify range as beginning line...then add a table 3x4
        Set Range = .ActiveDocument.Range(Start:=0, End:=0)
        .ActiveDocument.Tables.Add Range:=Range, NumRows:=3, NumColumns:=4
     'Set width of cell        
        .Selection.Tables(1).Columns.Width = InchesToPoints(1.5) 
     'move down 7 lines...
        .Selection.MoveDown Unit:=wdLine, Count:=7  
        .Selection.TypeParagraph
     'insert pagebreak...
        .Selection.InsertBreak Type:=wdPageBreak 
     'get last line in document...  
        Line = .ActiveDocument.Content.StoryLength - 1 
     'set range to last line        
        Set Range = .ActiveDocument.Range(Start:=Line, End:=Line) 
     ' add another table
        .ActiveDocument.Tables.Add Range:=Range, NumRows:=17, NumColumns:=17 
    End With


hope this helps
happy.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top