Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Filling formfields in Word.
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Filling formfields in Word.
Environment versions
Visual FoxPro:
VFP 8
OS:
Windows 2000 SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01222082
Message ID:
01222082
Views:
90
Hi all
I have been working in a little project for a customer.
It is a simple vfp form where invoices for a particular client are displayed, chosen one at a time and then at the click of a button, using automation, a Word template-based invoice is created.
The client wants a specific format and a .dot was provided.

In my laptop it works very well, but today, when demoing it, I got a "OLE dispatch exception code 0 from Microsoft Word: This method or property is not available because the object refers to a protected area of the document..." error for each form field I tried to fill (I used Word2003 in my laptop, over there they have Word2000, live and learn)

All goes down to this code, a function I call for every formfield:
*-- Create word application 
o = CREATEOBJECT("word.application")

*-- Create a document using template
IF llUseSingle 
	xx = o.Documents.Add(LCDOTPATH + "\XXX.dot")
ELSE
	xx = o.Documents.Add(LCDOTPATH + "\YYY.dot")
ENDIF 

FILLFIELD(CINVOICEDATE ,DTOC(curinvheader.dteinv))
FILLFIELD(CINVOICENO,curinvheader.invno)
.
.
FUNCTION FILLFIELD(cFieldName,cContent)
	o.ActiveDocument.FormFields.Item(cFieldName).Select
	*-- slow down a bit
        INKEY(0.1)
        *-- dirty trick to do a "select on entry" on the field
	o.Selection.Text = " "
	o.Selection.MoveRight(1,1)
	.Item(cFieldName).Select
        *-- slow down again
	INKEY(0.1)
        *-- Insert the content
	o.Selection.Text =  cContent
ENDFUNC
This code works well on Word2003 with a protected doc, but not in Word2000,
if I unprotect the document, fill fields and re-protect the document, the formfields will be overwritten, and the content will be unmodifiable, which is not good.

Please help, it should be doable, perhaps I'm not using the correct methods/objects.

TIA

Max

...Y soy feliz, bien feliz, asi lo grito;
Mira, que el mundo sepa, que se sepa:
Soy feliz....                       

...And I'm happy, quite happy, so do I yell it;
Look, so the world knows it, so be known:
I'm happy...
 

Ismael Rivera "Oye cosita linda"
Next
Reply
Map
View

Click here to load this message in the networking platform