Access-Word Automation Problem in Office 2003

J

JP

I have an Access application that drives data into FormFields in Word docs.
The word docs are protected (Tools|Protect Document). The basic code is
below:

Dim wordApp As Word.Application
Dim worddoc As Word.Document

Set wordApp = CreateObject("Word.Application")
Set worddoc = wordApp.Documents.Open(FOLDER_NAME & sWordDocName, False,
True, False, , , True, , , , , False)

worddoc.FormFields("Field1").Result = "abcdef"

The application works fine under Access 2000/Win2K/Office 2K, Access
2002/Win2K/Office 2002, Access 2000/XP/Office 2K, Access 2002/XP/Office 2002
but fails under Office 2003 (Access 2003/XP/Office 2003.

The error code is -2147417851 and the message is "Method result of object
formfield failed". The error occurs when executing the .result command.

Anybody have any thoughts/experience with this? I can't find anything in
the KB yet.

Thanks.
 
C

Cindy M -WordMVP-

Hi Jp,

I just set up a quick test and don't see any problems. You're absolutely
certain there's a form field in the document with the name "Field1"? Are you
able to manipulate the document, otherwise (i.e. remove protection and put
text in a range)? Are you sure the document is not being opened "read-only" or
has some kind of permissions problem?

Here's the code I used:

Option Compare Database
Option Explicit

Public Function StartWord() As Word.Application
Set StartWord = CreateObject("Word.Application")
End Function

Public Function GetWordInstance() As Word.Application
Set GetWordInstance = GetObject(, "Word.Application")
End Function

Sub PutDataIntoWordFormField()
Dim wdapp As Word.Application
Dim wddoc As Word.Document

On Error Resume Next
Set wdapp = GetWordInstance
If Err.Number = 429 Then
Set wdapp = StartWord
End If
On Error GoTo 0

Set wddoc = wdapp.Documents.Add
wddoc.FormFields.Add Range:=wdapp.Selection.Range,
Type:=wdFieldFormTextInput
wddoc.Protect wdAllowOnlyFormFields
wddoc.FormFields("Text1").result = "abc"
wdapp.Visible = True
wdapp.Activate
Set wddoc = Nothing
Set wdapp = Nothing
End Sub

I have an Access application that drives data into FormFields in Word docs.
The word docs are protected (Tools|Protect Document). The basic code is
below:

Dim wordApp As Word.Application
Dim worddoc As Word.Document

Set wordApp = CreateObject("Word.Application")
Set worddoc = wordApp.Documents.Open(FOLDER_NAME & sWordDocName, False,
True, False, , , True, , , , , False)

worddoc.FormFields("Field1").Result = "abcdef"

The application works fine under Access 2000/Win2K/Office 2K, Access
2002/Win2K/Office 2002, Access 2000/XP/Office 2K, Access 2002/XP/Office 2002
but fails under Office 2003 (Access 2003/XP/Office 2003.

The error code is -2147417851 and the message is "Method result of object
formfield failed". The error occurs when executing the .result command.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 
J

JP

Cindy,

Thanks for the reply.

I'm sure it's working in the other environments, it's just not working in
the Office 2003 environment.

I will try substituting your code for the code I have and see if it helps.

Is there anything special that needs to be done in installing Office 2003
that could account for the problem? Maybe an optional feature that is not
part of the normal install? I've seen references to PIAs in Office 2003 --
would they have anything to do with the problem?

JP
 
C

Cindy M -WordMVP-

Hi Jp,
I'm sure it's working in the other environments, it's just not working in
the Office 2003 environment.

I will try substituting your code for the code I have and see if it helps.

Is there anything special that needs to be done in installing Office 2003
that could account for the problem? Maybe an optional feature that is not
part of the normal install? I've seen references to PIAs in Office 2003 --
would they have anything to do with the problem?
I know of nothing, in particular, in Word 2003 that would make this behave any
differently; I did test under Office 2003.

PIAs only have to do with automating a COM aplication using the NET framework.
You don't mention NET anywhere, so I don't think that's relevant...

The error message you quote indicates that something is not allowing the
..Result property to accept what you're trying to give it. But if you're trying
to pass it a literal string, that shouldn't be a problem, as long as the form
is protected.

Of course, if you didn't show us the actual code you're using (and it looks to
me very much as if you did not), then it's rather difficult to make any
guesses.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 
J

JP

Cindy,

Thanks for all your help.

I finally got the thing working by using your code and then line by line
substituting my code until it stopped working.

By the way, the code I posted was actual code that wasn't working.

The problem turned out to be the open:

Set worddoc = wordApp.Documents.Open(FOLDER_NAME & sWordDocName, False,
True, False, , , True, , , , , False)

When I replaced it with

Set worddoc = wordApp.Documents.Open(FOLDER_NAME & sWordDocName, , True)

everything started working. I'm not sure why the open would work in Access
2000 and Access 2002, but not Access 2003.

Thanks again
 
C

Cindy M -WordMVP-

Hi Jp,
The problem turned out to be the open:

Set worddoc = wordApp.Documents.Open(FOLDER_NAME & sWordDocName, False,
True, False, , , True, , , , , False)

When I replaced it with

Set worddoc = wordApp.Documents.Open(FOLDER_NAME & sWordDocName, , True)

everything started working. I'm not sure why the open would work in Access
2000 and Access 2002, but not Access 2003.
From the way it looks, I'd guess that one of the parameters changed - it
shouldn't happen, of course, but on occasion MS makes such a mistake. On the
whole, I usually prefer to work with named parameters if the programming
environment supports it (which Access does if you have a reference to the Word
object library) to avoid such "misunderstandings".

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
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 :)
 

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