Solved

Microsoft Word Create Nested table within a table

Posted on 2008-06-24
4
1,835 Views
Last Modified: 2013-11-27
newtbl = wrdDoc.Tables.Add(wrdRow.Cells(z), 2, 3)
see the above line in the code snippet.

I am trying to create a 2 column x 3 row table nested in a cell using Microsoft Access and this attempt returns Type mismatch err 13.

How can I create a table inside a table in the context of the code provided?
I'm stuck..
Thanks!
'ITEMS AND SALES ARRIVE TO THIS FUNCTION
 

    Dim wrdApp  As Word.Application

    Dim wrdDoc  As Word.Document

    Dim wrdTbl  As Word.Table

    Dim wrdRow  As Word.Row

 

  

    

    strTmp = CurrentProject.Path & "\Sales-Sheet-Tailsheet.doc"

    strTail = "C:\SALEDB\DocPrep\TailSheet.doc"

        FileCopy strTmp, strTail

    Set wrdApp = New Word.Application

    Set wrdDoc = wrdApp.Documents.Open(strTail)

    Set wrdTbl = wrdDoc.Tables(1)

 

    

    'wrdTbl.Rows.Add

    Set wrdRow = wrdTbl.Rows.Last

    wrdRow.Cells.Add

    wrdRow.Cells.Add

    wrdRow.Cells.Add

    wrdRow.Cells.Add

    wrdRow.Cells.Add

    wrdRow.Cells.Add

    wrdRow.Cells.Add

    

 

            If bldghandled = False Then

            building_fields = "SQFT:USETYPETEXT"

            building_count = 2

            'merge cells

            wrdRow.Cells(z).Merge wrdRow.Cells(z + 1)

            'add table

            newtbl = wrdDoc.Tables.Add(wrdRow.Cells(z), 2, 3)

            

     

            End If

    

 

Set wrdDoc = Nothing
 
 

'close the word doc

wrdApp.Quit True  'true is for saving changes
 

Set wrdApp = Nothing

Open in new window

0
Comment
Question by:KeithMcElroy
  • 3
4 Comments
 
LVL 27

Expert Comment

by:MikeToole
Comment Utility
WHich statement triggers the error?
0
 
LVL 27

Expert Comment

by:MikeToole
Comment Utility
The posted code doesn't include the declarations of any of the variables in the attached snippet - important information for a Type mismatch error!
            If bldghandled = False Then

            building_fields = "SQFT:USETYPETEXT"

            building_count = 2

            'merge cells

            wrdRow.Cells(z).Merge wrdRow.Cells(z + 1)

            'add table

            newtbl = wrdDoc.Tables.Add(wrdRow.Cells(z), 2, 3)

            

     

            End If

Open in new window

0
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
Comment Utility
<            newtbl = wrdDoc.Tables.Add(wrdRow.Cells(z), 2, 3)>
This line needs to be:
            set newtbl = wrdDoc.Tables.Add(wrdRow.Cells(z).Range, 2, 3)
However, using Office 2007 I found that only one row was inserted in the new table no matter what is specified in the NumRows parameter. To get two rows, add this statement:
            newtbl.row.add
0
 

Author Closing Comment

by:KeithMcElroy
Comment Utility
Awesome.  I appreciate the help.  Worked beautifully!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now