Solved

VFP automation fails after upgrade to Word 2010

Posted on 2014-10-13
18
486 Views
Last Modified: 2014-11-01
Since upgrading from Word 2007 to Word 2010, the statement below in one of our VFP6 applications fails with error "OLE error code 0x80004005: Unspecified error."  Does anyone have any ideas on what might have changed in Word or what might be missing from its installation to cause this bad behavior?

obox = odocshapes.addtextbox(1,nleft,ntop,nwidth,nheight)
0
Comment
Question by:GEOFS
  • 8
  • 6
  • 3
  • +1
18 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
Comment Utility
please post your sample code here.
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
It is hard to say what causes this unspecified error.

Could you please post a piece of code which we may test in our environment?

You should also disclose the OS version and Word version (32 vs. 64 bit). VFP 6 SP version would also tell more.

Does your code fail when you test it in VFP 6 IDE or does it happen just in application EXE? Did you even try it in VFP 9? Does it happen on all computers having the same configuration?

More questions:
Can you create different control in your Word document? (means e.g. checkbox)
Are you sure the control creation is not blocked in the Word document?

Newer Word version compatibility is not 100% guaranteed, some parameters are not supported as before, you have to test everything and find some work around obviously.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
As a general recommendation put a DOEVENTS FORCE After Createobject("Word/Excel/Outlook/InternetExplorer/other.Application") and you can use the resulting object reference for automation.

I don't know what plays a major role, new Office Versions, new Windows Versions, Multi Core CPUs, if you skip the DOEVENTS FORRCE you get an automation object reference to a not yet fully loaded and ready object and all kind of errors occur, when addressing it, or it's collections, etc.

Also I'm with Kalpesh, if you post your code, that would be helpful to see what might go wrong otherwise.

Bye, Olaf.

PS: Since Pavel also mentions it, I see you're at VFP6, then you don't have the FORCE clause of DOEVENTS, WAIT TIMEOUT 0.5 could also help or DOEVENTS without the force clause.
0
 
LVL 2

Author Comment

by:GEOFS
Comment Utility
Kalpesh/Pavel/Olaf:  Thanks to all of you for responding.  The code in question is part of FRX2WORD, an old VCX which transforms Fox reports directly into Word documents.  The only Fox code involves creating an instance of the class, setting a few properties and calling the method to process the report.  Here's what it looks like:

        set classlib to msoexp
        of2w = newobject("frx2word","msoexp")
        of2w.SaveFolder  = mvolume+"\sc2\emails\"
        of2w.doc_filename = alltrim(mrtfname)+".doc"
        of2w.cscope = "next 1"  
        nsuccess = of2w.reportform("&qpfrm")

FRX2WORD was originally built by John Koziol and later taken over by Fabio Viera,  I have contacted Fabio, who told me that he no longer uses or supports the software.  He suggested that I replace it with a more recent product called FoxyPreviewer.  We would rather not make such a major change to the app and its environment because it is due to be replaced in a (hopefully) few more months.

The app is run via Citrix on a 64-bit machine running Windows Server 2008 R2 Enterprise.  The VFP6 version is 06.00.8167.00.
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
Foxypreviewer needs VFP 9, frx2word is unsupported, you are not sure this is the only error in W2010 OLE automation, you need just a few more months, ...

The easiest solution seems to be to downgrade the Word to 2007 version.

Or, perhaps, could you check by some Process Monitor what happens before the error rises?

Another option is XFRX: http://www.eqeus.com/
It supports output to DOC format in VFP 6.
0
 
LVL 2

Author Comment

by:GEOFS
Comment Utility
Here are answers to more of Pavel's questions:

The Citrix desktop environment uses Word version 14.0.7128.5000 (32-bit), part of MS Office Professional 2010.

The error occurs for all users running the app in this Citrix desktop with Word 2010.  The app runs fine in the previous Citrix desktop with Word 2007.  We cannot upgrade the app to VFP9 but I have found out that the code below runs without complaint in the VFP9 IDE in the Citrix desktop with Word 2010:

oWord = CREATEOBJECT("Word.application")
oWord.Visible = .t.
oDoc = oWord.Documents.ADD()
FOR i = 1 TO 10
      oBox = oDoc.Shapes.addtextbox(1,10,(100*(i-1)),100,100)
      oBox.TextFrame.TextRange = TRANSFORM(i)
ENDFOR
* Halt execution so we can take a look at the output.
MESSAGEBOX( "Check out the textboxes." )
oWord.Documents.CLOSE(0)
oWord.Quit

The odd thing about this bit of code is that it generates only one page with the first 8 textboxes, suggesting that it has some problem dealing with the second page.  It seems that the same sort of thing is happening in the app, that is, the problem only occurs on the second page of report output.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
>The code in question is part of FRX2WORD, an old VCX
...
>The odd thing about this bit of code is that it generates only one page with the first 8 textboxes, suggesting that it has some problem dealing with the second page.

Well, you describe perfectly, what I experienced some time ago.
1. It's code that was tested in time and worked beforehand
2. It fails not only on adding and acting on a first page/document/sheet, but on the second one.

And what helped - not in just one case - was to use the application object after waiting a bit. Give it a try.

I didn't need to change code for Word and Excel and Outlook automation creating documents/reports/mails, all continued to worked as before after adding DOEVENTS FORCE and a colegue of me simply used WAIT TIMEOUT 0.5 in an older VFP7 application. The change is really outside of VFP, but it's not in the object model of Office applications, it's in the way it initialises, it has to be there.

It's a bit like Windows itself, right after starting it you may get a first app running right after login (eg a browser), then Windows gets unresponsive again and after a bit waiting you can really start using Windows. Seems like MS has done something accelerating the response of COM object instantiation, yet delivering a not yet fully ready object.

I've suggested the DOEVENTS FORCE solution several times and nobody seemed to believe me, though I solved several problems in different applications myself with it.

Bye, Olaf.
0
 
LVL 2

Author Comment

by:GEOFS
Comment Utility
Thanks for the tip, Olaf.  We'll give it a try.
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
Sorry I have to say that: I am pessimist in this case.  The first page is OK, why should the wait command help? But who knows...

Lets wait...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
It already happened - reproducible. Why? Don't ask me. Maybe some delayed initialisation (in an event queue) makes the object unresponsive, then it hangs and errors. DOEVENTS FORCE or alternatively waiting a second lets this event happen and it doesn't get in the way afterwards.

Remember how people were puzzled about the Internetexplorer.Application Object not working and only later the behaviour could be explained by protected mode?

What happened is explained here: http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx

I assume something similar to what is described in the paragraph "Losing Control". A switch of some process renders the already used COM reference invalid.

Bye, Olaf.
0
 
LVL 2

Author Comment

by:GEOFS
Comment Utility
We have tried putting the WAIT TIMEOUT with various time values at several points in the code (e.g., after the CREATEOBJECT("Word.Application"), just before the new page code and just before the AddTextBox), but it still fails.  It seems as though something gets deleted or released during the transition from the first page to the second.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
How about single stepping through the code (debugger). If you identified the line causing the error, check out oWord right before that line, see what intellisense shows.

Bye, Olaf.
0
 
LVL 2

Author Comment

by:GEOFS
Comment Utility
The oWord object is still defined immediately before the call to AddTextBox().  We're testing the possibility of producing an RTF document instead of a DOC.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
It's a good idea to look for alternatives.

In regard to debugging: It never was in question the variable oWord still exists. The variable itself is a VFP thing, the word process can't kill a VFP variable, that also wasn't the problem with the internet explorer protected mode issue.

The thing to check at that point is, whether intellisense can still drill down into any section of the Word object model and do other things, eg select some range, set word visible or hide it, add a new document, anything but the failing AddTextBox. If only AddTextBox fails, it may simply be a deprecated feature of this Word version. If it works before this instance of adding another textbox you'll need to dig deeper into differences in the outset, eg selected range, page, whatever plays a role.

Bye, Olaf.
0
 
LVL 2

Author Comment

by:GEOFS
Comment Utility
The object that contains AddTextBox, oDocShapes, is still defined, including the method, when AddTextBox is called.  The method works without complaint on the first page of the document; it then fails on the second page.

We have discovered that the issue may be related to the compatibility mode operation of Word 2010, although we haven't figured out how to use that to help solve the problem.  However, we have confirmed that the method does not fail when the document type is RTF instead of DOC.  This seems counter-intuitive to me, but at least we have a way to use the old program in the new environment.

Thanks, Olaf, for all of your suggestions.
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 500 total points
Comment Utility
Second page means what? I don't think the same Shape will be usable for a textbox on the second page.
The situation when you add a textbox on the other page is interesting, of course, not the situation for the working textbox.

Overall it speaks for a split of Word processes, when you add objects. The automation object you get in VFP, any automation object can only be valid for one process. Finally that means a change of word causes that incompatibility with FRX2ANY. MS should be addressed to look into this. Isolating a repro scenario would be good.

I know you can control how and whether IE creates new processes for new tab with registry keys, but find nothing similar for Word.

Bye, Olaf.
0
 
LVL 2

Author Comment

by:GEOFS
Comment Utility
We've done some testing with RTF files instead of DOC files and, for whatever reason, that seems to work.  I'm going to expand the test to include more users next week and keep my fingers crossed.

Thanks again, Olaf, for your suggestions.
0
 
LVL 2

Author Closing Comment

by:GEOFS
Comment Utility
The problem hasn't actually been solved but, in light of Olaf's persistence in his effort to find a solution, I think he deserves the credit.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now