Server threw an exception

P

paxdominus

Greetings,

I'm working with Access 2002 and Word 2002.

I'm taking OLE objects (Word Documents) and embedding them into a table
in another Word Document, so far so good.

If I get two such objects on one page (each row of the table is a
page), then I need to find out the height of each object, subtract the
total of their heights from the total height of the page, if there is
available space left, then I need to adjust the height of the first
object. If it is less than 1/2 a page, then I need to make it 1/2 a
page in height, if it's more than 1/2 a page, then to leave it alone.
Then I need to put a line across it's bottom border.

All of that works fine in Word, but when I put it into Access, I get
either:

Automation Error: The server threw an exception.

or

Method 'Height' of object 'InlineShape' failed.

depending on how I reference the appropriate InlineShape.

I have late-bound everything (I have to for the way all of our
automation works). I have removed the Word reference and no errors
occur.

The code for this is below. Note on the code, all of the Word
properties (e.g., wdSaveChanges) I have set as global constants (e.g.,
wrdSaveChanges = 1) so as to remove all reference to Word, but to keep
clarity of what property I'm referencing.

Code
*********

Public Sub Something()

Dim sglHeightOfFirstObject As Single
Dim sglHeightOfSecondObject As Single
Dim sglNewHeight As Single
Dim sglTotalHeight As Single
Dim sglPageHeight As Single
Dim sglHalfPage As Single
Dim sglAvailableSpace As Single
Dim sglPadder As Single
Dim sglHeightFromTop As Single

Dim objFirstObject As Object
Dim objSecondObject As Object
Dim wObj4 As Object
Dim wDoc4 As Object
Dim wAct4 As Object
Dim wSel4 As Object

Dim intNumberOfIShapes As Integer

Dim strNewSave As String

sglPageHeight = 654
sglHalfPage = 324

Set wObj4 = GetObject(, "Word.Application")
Set wDoc4 = GetObject("", "Word.Document")

strNewSave = wobj4.ActiveDocument.Fullname

Set wAct4 = wObj4.Documents(strNewSave)
Set wSel4 = wObj4.Selection

intNumberOfIShapes = wAct4.InlineShapes.Count

Set objSecondObject = wAct4.InlineShapes(intNumberOfIShapes)
Set objFirstObject = wAct4.InlineShapes(intNumberOfIShapes - 1)

sglHeightOfSecondObject = objSecondObject.Height
sglHeightOfFirstObject = objFirstObject.Height

sglTotalHeight = sglHeightOfFirstObject + sglHeightOfSecondObject

sglAvailableSpace = sglPageHeight - sglTotalHeight

If sglAvailableSpace > 42 Then
sglPadder = sglAvailableSpace - 24
Else
sglPadder = 0
End If

If sglHeightOfFirstObject > sglHalfPage Then
sglNewHeight = sglHeightOfFirstObject
Else
sglNewHeight = sglHeightOfFirstObject + sglPadder
If sglNewHeight >= sglHalfPage Then
sglNewHeight = sglHalfPage
End If
End If

wSel4.HomeKey unit:=wrdStory

' Error occurs at the next line, if it is like the uncommented
line, then
' I get the "Server threw an exception error"
' If I use objFirstObject.Height = sglNewHeight then I get the
"Method ..."
' error.

wAct4.InlineShapes(intNumberOfIShapes -1).Height = sglNewHeight

objFirstObject.Select

With wSel4
With .Borders(wrdBorderBottom)
.LineStyle = wrdLineStyleSingle
.LineWidth = wrdLineWidth050pt
.Color = wrdColorAutomatic
End With
.Borders.Shadow = False
End With

wSel4.MoveRight unit:=wrdCharacter, Count:=1
wSel4.TypeParagraph

wAct4.Save

Set wSel4 = Nothing
Set wAct4 = Nothing
Set wDoc4 = Nothing
Set wObj4 = Nothing

End Sub

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top