Access 2000/Word automation question.

B

Brian Wissert

Hi everyone,

I am working with Access 2000, VBA, OLE automation, and Word 2000

I have a table in access that contains an ID and an embedded word document.
I am trying to activate the document and search for a keyword. When I find
this word I want to highlight it in yellow wherever it appears in the
document. I keep crashing.

Here is my code:

Private Sub btnActivate_Click()
Dim ctl As Control
Dim strSearch As String
Dim appWD As Word.Application
Dim rngTemp As Range
Dim myDoc As Document

Forms![CEO Resume Search]!txtKeyword.SetFocus
strSearch = txtKeyword.Text

'Open the Word document for editing
'This works, the word app opens with the embedded document showing.
Set ctl = Me!OLEBoundResumeView
With ctl
' Set Locked property to False.
..Locked = False
' Set Verb property to activate for editing.
..Verb = acOLEVerbOpen
' Activate object.
..Action = acOLEActivate
End With

Set appWD = GetObject(, "Word.Application")
appWD.Options.DefaultHighlightColorIndex = wdYellow
'This works, the word app opens and the highlight function is set to yellow.
Set myDoc = Documents(1)

With myDoc.Content.Find
'This is my problem area
..ClearFormatting
..Text = strSearch
..Replacement.ClearFormatting
..Replacement.Text = strSearch
..Replacement.Highlight = True
..Execute FindText:=strSearch, ReplaceWith:=strSearch, Format:=True,
Replace:=wdReplaceAll
End With
End Sub



When I run the code, I get an error, -2147220995 - Object is not connected
to server. Then access crashes. Oops.

It correctly sets the highlighting color index to yellow within the opened
Word application, so I know that I am communicating with Word.

I think I am probably referencing the object incorrectly. It crashes when I
start to use the Find code.

Any help would be greatly appreciated.

Thank You
 
C

Cindy Meister -WordMVP-

Hi Brian,

There's a known problem when automating Word from another
app and using the Find/Replace functionality. See this KB
article

BUG: Automation Client Receives Error Calling Word Find
Object [Q292744]
http://support.microsoft.com?kbid=292744
With myDoc.Content.Find
'This is my problem area

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jan 24 2003)
http://www.mvps.org/word

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

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