Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Microsoft Word Create Nested table within a table

Posted on 2008-06-24
4
Medium Priority
?
1,854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 27

Expert Comment

by:MikeToole
ID: 21863622
WHich statement triggers the error?
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 21863651
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 2000 total points
ID: 21864149
<            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
ID: 31470415
Awesome.  I appreciate the help.  Worked beautifully!
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

636 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