View Single Post
  #2   Report Post  
Posted to microsoft.public.word.tables
Cindy M -WordMVP- Cindy M  -WordMVP- is offline
external usenet poster
 
Posts: 370
Default memory could not be read error using tables in MS Word 2003

Hi ?B?U2Ft?=,

First of all, put your code in Try...Catch blocks so that you can track down
what line(s) are responsible for the problem.

Is this your exact code, or just a simplified rendition? There's a common
error with Word automation if you do a lot of formatting work. The
scratch/temp/Undo files can't keep up. In the Word interface we get a message
about the formatting being too complex, and since the problem most often
comes up when generating and formatting tables, I have to wonder if that
could be what this is.

If you search the msdn website on my name you should turn up an article about
efficiently generating tables in Word. See if constructing your code along
those lines helps at all. And also note how to work with Word's objects
(Table and Row).

I am trying to create a word document programatically in vb.net 2003.The
program would create a blank word document, insert a table and populate it
with some values.
my program does successfully create the word document, inserts table and
populates it.The probelm I am running into is that just before the program
ends I get the following error message:
Application Error: The instruction at "0x5b261e4e" referenced memory at
"0x0454e2c8". The memory could not be "read" Click on OK to terminate the
program.

I dont get this error message if I insert sentences instead of table.

Here's the code snippet that inserts table:

With currentSelection
Dim sTableRng As Word.Range = sWord.Selection.Range

sDoc.Tables.Add(sTableRng, sRowCount, sColCount)

'Add table row headings
With sDoc.Tables.Item(1)
'Format the headings
.Cell(1, 1).Range.Font.Bold = True
.Cell(1, 2).Range.Font.Bold = True
.Cell(1, 3).Range.Font.Bold = True

'Enter heading names
.Cell(1, 1).Range.Text = "Item Name"
.Cell(1, 2).Range.Text = "Type"
.Cell(1, 3).Range.Text = "Width"
End With

'Add values into the table
'Declare variable to iterate through rows of table
Dim sTI As Integer

'Enter field values
For sTI = 2 To sRowCount + 1
With sDoc.Tables.Item(1)
'Format the headings
.Cell(sTI, 1).Range.Font.Bold = False
.Cell(sTI, 2).Range.Font.Bold = False
.Cell(sTI, 3).Range.Font.Bold = False

'Enter heading names
.Cell(sTI, 1).Range.Text = "Item1"
.Cell(sTI, 2).Range.Text = "Type1"
.Cell(sTI, 3).Range.Text = "Width1"
End With
Next
sTableRng = Nothing
End With

I tried the releaseCOMobject method at the end to close any open
connections, but that did not help either.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)