Failure of Word 2003 Range.Find object in Access 2003 automation

R

Rod Scoullar

A VBA procedure that has worked in Office 2000 is failing when run in 2003.

The procedure uses automation to merge data from an Access database into a
Word file. Some of the data merged are themselves Word documents. These
require several fields merged following their insert. This has been
accomplished by using search and replace as a pseudo merge.

The included documents have name and ID code specified as <<Name>> and
<<ID>> and these are replaced following the merge by the appropriate values.

In 2003 merge succeeds but the search and replace fails. The Find object of
the Range object cannot be referenced and the Access application closes when
this is attempted.

Any help would be appreciated. The relevant VBA code is shown below.

Rod Scoullar

----------

Dim objWord As Object
Dim objAcc As Object
Dim strHold As String
Dim strName As String
Dim strPNum As String


objWord.Documents.Open (strDocName)

objWord.Visible = True

' do the merge

With objWord.ActiveDocument.MailMerge
.OpenDataSource Name:="C:\UHGLifetrack\LTMM.txt",
Format:=wdOpenFormatText, ConfirmConversions:=False

' save the name and id for use in the search and replace

strName = .DataSource.DataFields("PatientFirstName").Value & " " &
..DataSource.DataFields("PatientLastName").Value
strPNum = .DataSource.DataFields("PolicyNumber").Value
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute
End With

objWord.ActiveDocument.Select
objWord.Selection.Fields.Update
objWord.Selection.Collapse

' set range object to point to document content

Dim rng As Range
Set rng = objWord.ActiveDocument.Content

**** rng.Find.Text = "<<Name>>" **** fails at this point

rng.Find.Replacement.Text = strName
rng.Find.Execute Replace:=wdReplaceAll
 
C

Cindy M.

Hi =?Utf-8?B?Um9kIFNjb3VsbGFy?=,
The Find object of
the Range object cannot be referenced and the Access application closes when
this is attempted.
See if the information in this KB article covers the problem:

http://support.microsoft.com/kb/292744/EN-US/

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 :)
 
R

Rod Scoullar

Thanks for the response Cindy.

I'm not sure that the ambiguous GUID reference was the problem but it was a
very real possiblility. I don't know how you managed to know of that issue.

The problem 'went away' when I changed the reference from a Range.Find to a
Selection.Find. This is the way the record macro did the search and replace.
I should have notified the newsgroup but I had given up on getting a
response by the time I came up with the solution.

Thanks again for your input. It was (and is) much appreciated.
 

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