hi Peter
Thanks for your replay, but it seems i didn't make myself
clear.
I have, let's say 3 records,( actually it varied, can be
much more then 3 records). and for each record i have to
create a table of 33 rows and 4 colomns (constant)
each table has tobe located in a different page of the
active document.
my biggest problem is to rerange the new range, for the
new table, because such line:
Set oTable = oRange.Tables.Add(oRange, _
rs.RecordCount + 1, rs.Fields.Count)
gives the meassge 'oRange' can not be erase (or something
like this)
i hope you have the enrgy to write a detailed answer as
you wrote earlier
many many thanks in advance
joy
-----Original Message-----
Hi joy
Someone e;se (or was it you?) wanted to do the same
thing. Here's what I posted last
time, I hope it's of help to you:
Public Sub CreateWordTable(ByVal rs As DAO.Recordset, _
ByVal strFilePathAndName As String)
Const RECORDS_Per_Page As Long = 33
'this code will require a reference to Word
On Error GoTo ProcError
Dim appWord As Word.Application
Dim docNew As Word.Document
Dim oTable As Word.Table
Dim oRange As Word.Range
Dim fld As DAO.Field
Dim f As Long
Dim lngColumn As Long
Dim r As Long
'now lets see what we get with Word
On Error Resume Next
'delete file if exists
If LenB(Dir$(strFilePathAndName)) > 0 Then Kill strFilePathAndName
'Attempt to reference Word which may already be running.
Set appWord = GetObject(, "Word.Application")
If appWord Is Nothing Then
'Word is not running, better try and start it
Set appWord = CreateObject("Word.Application")
'Now if appWord Is Nothing, MS Word is not installed.
If appWord Is Nothing Then
MsgBox "MS Word is not installed on your computer"
GoTo ExitHere
End If
End If
'reset to regular error handling
On Error GoTo ProcError
With appWord
.Visible = True
Set docNew = .Documents.Add
Set oRange = docNew.Content
Set oTable = oRange.Tables.Add(oRange, _
rs.RecordCount + 1, rs.Fields.Count)
oTable.AutoFormat Format:=wdTableFormatClassic2
End With
With oTable
Do Until rs.EOF
' Table must have a header row
If rs.AbsolutePosition = 1 Then
.Rows(1).HeadingFormat = CLng(True)
' Insert table header row here
End If
' Force this row to start on a new page
If rs.AbsolutePosition Mod 33 = 0 Then
.Cell(rs.AbsolutePosition, lngColumn).Range. _
Paragraphs(1).PageBreakBefore = True
End If
' Transfer record to the table
For lngColumn = 1 To oTable.Columns.Count
.Cell(rs.AbsolutePosition,
lngColumn).Range.Text = rs(lngColumn - 1)
Next
rs.MoveNext
Loop
End With
docNew.SaveAs strFilePathAndName
ExitHere:
appWord.Documents.Close
appWord.Quit
Set oTable = Nothing
Set appWord = Nothing
Exit Sub
ProcError:
Select Case Err.Number
Case Else
MsgBox "Unanticipated error " & Err.Number & " " & _
Err.Description & " Aborting!"
Stop
Resume 0 'Hit F8 to goto line with error
End Select
End Sub
I've added an extra row to your table to contain the
header information. I don't know
what text you require in the header row so you'll need to
add this. On every 33rd record
the code sets the Paragraph formatting to
be "PageBreakBefore", this causes that row to
start on a new page.
Depending on the version of Office you intend to use you
may wish to consider dumping the