Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
accdev accdev is offline
external usenet poster
 
Posts: 3
Default How to add a table using vb

While in Access 2003 I've been generating data into a word (2003) template.
Up to now there has been only one table which is entered on the template.

Now my user wants me to break down his data by an AgencyOffice field and
have each office in their own table. There will be some totals after each
group. However, I'm not concerned with the totaling in this question. Nor
am I concerned about how to determine when to create a new table by keeping
track of the AgencyOffice field. What I need to know is how I go about
creating a new table with the attributes of the table that is already there.
Or maybe there is another way to do this? By the way, I usually know enough
about Access vb to do what I need to do, but I'm pretty ignorant about Word
vb.

I've only entered two fields below (there are several) but this is
essentially what I'm currently doing in Access.

Dim db As Database
Set db = DBEngine.Workspaces(0).Databases(0)
Dim wordobj As Object
Dim sTemplatename As String
sTemplatename = pubTemplateFolder & "AgencyBill.doc"
Set wrdobj = CreateObject("Word.application")
wrdobj.Documents.Add sTemplatename
Set rs = CurrentDb.OpenRecordset("WDBillData")
rs.MoveLast
rs.MoveFirst
' Write details info into table in Word Document
For inti = 0 To rs.RecordCount - 1
wrdobj.ActiveDocument.Tables(1).Cell(inti + 1, 2).Range =
Trim$(Left(rs.FullName.Value, 24) & "")
wrdobj.ActiveDocument.Tables(1).Cell(inti + 1, 4).Range =
Format(rs.amount.Value, "##0.00") & ""
rs.MoveNext
If rs.EOF Then Exit For
wrdobj.ActiveDocument.Tables(1).Rows.Add
Next
rs.Close
  #2   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default How to add a table using vb

To get the tables the same, it might be easier to write all of the data to
the one table and then include code to locate the rows that have the
AgencyOffice field in them and then split the table at that point (or add
the first row of data for the new AgencyOffice and then split the table at
that row, keeping track of the number of tables in the document and
incrementing the table index by one each time it is split.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"accdev" wrote in message
...
While in Access 2003 I've been generating data into a word (2003)
template.
Up to now there has been only one table which is entered on the template.

Now my user wants me to break down his data by an AgencyOffice field and
have each office in their own table. There will be some totals after each
group. However, I'm not concerned with the totaling in this question.
Nor
am I concerned about how to determine when to create a new table by
keeping
track of the AgencyOffice field. What I need to know is how I go about
creating a new table with the attributes of the table that is already
there.
Or maybe there is another way to do this? By the way, I usually know
enough
about Access vb to do what I need to do, but I'm pretty ignorant about
Word
vb.

I've only entered two fields below (there are several) but this is
essentially what I'm currently doing in Access.

Dim db As Database
Set db = DBEngine.Workspaces(0).Databases(0)
Dim wordobj As Object
Dim sTemplatename As String
sTemplatename = pubTemplateFolder & "AgencyBill.doc"
Set wrdobj = CreateObject("Word.application")
wrdobj.Documents.Add sTemplatename
Set rs = CurrentDb.OpenRecordset("WDBillData")
rs.MoveLast
rs.MoveFirst
' Write details info into table in Word Document
For inti = 0 To rs.RecordCount - 1
wrdobj.ActiveDocument.Tables(1).Cell(inti + 1, 2).Range =
Trim$(Left(rs.FullName.Value, 24) & "")
wrdobj.ActiveDocument.Tables(1).Cell(inti + 1, 4).Range =
Format(rs.amount.Value, "##0.00") & ""
rs.MoveNext
If rs.EOF Then Exit For
wrdobj.ActiveDocument.Tables(1).Rows.Add
Next
rs.Close



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form with table - Extend length of table as needed by user's input RogerC Microsoft Word Help 3 November 6th 07 01:58 PM
Sort text in table - ascending results drop to bottom of table! Hanging out Microsoft Word Help 1 August 10th 06 10:32 PM
Need macro to locate table uniquely, insert blank row and date and end table Marrick13 Tables 4 July 1st 06 12:33 PM
Toolbar option available for TABLE>INSERT>TABLE to enclose text into a table? StargateFan New Users 5 January 29th 05 11:10 PM
...
in text file convert to Word table.
Bill_McC Tables 1 January 27th 05 03:47 PM


All times are GMT +1. The time now is 08:07 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"