Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Office 2007 breaks word Automation
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01331039
Message ID:
01344945
Views:
24
I wanted everyone to know that I did fix my issue with Word2007. It was really simple but way time consuming. I want everyone to know that 2 datasources can be used on ONE document. I use mergefields and an embedded {database} query pointing to DBF's (free tables). The Word2007 documents use an "odc" xml doc to point to one datasource. The embedded query points to different datasource.

I had 2 issues;
1. "Word cannot open document as a data or header source because it contains no data."
2. Word2007 documents with mergefields stays dynamic after saving. (reprinting a merged doc gives displays the data currently in the data, not the data originally merged)

Solution:
1. The solution in the book "MS Office Automation with VFP" for attaching data to a word doc DOES NOT work in Word2007. That means NO data doc and NO header doc to merge. Here is my code:
*! oDoc = the document object
*! psConn = odc file name
*! psGrpId = saveas file name
LPARAMETERS oDoc, psConn, psGrpId
oDoc.MailMerge.OpenDataSource(oApp.DbfPath+psConn)

If oDoc.MailMerge.State = 2 && 
               * always use a table for datasource with 1 record for mergefields
	oDoc.MailMerge.DataSource.FirstRecord = 1
	oDoc.MailMerge.DataSource.LastRecord = 1
	oDoc.MailMerge.Destination = 1 && send to printer on execute
	oDoc.MailMerge.Execute
	wait "" timeout 5	&& give doc 5sec to print because of Off2007
else
	MESSAGEBOX("",16,"NO Data Attached to Document")
	
endif
* save memo_pn.doc for future printing
IF LOWER(SUBSTR(oDoc.name,RAT('_',oDoc.name)+1,2)) = "pn"
	lsName = oApp.UserPath+psGrpId+"Lst.doc"
	oDoc.MailMerge.MainDocumentType = -1 && wdNotAMergeDocument - keeps as static data
	oDoc.SaveAs(lsName)
ENDIF 
This next code is what I embedded to display table of data 4 columns wide into a mergefield.
The table (in the mergefield) has to be formated with the maximum number of rows you expect you may display/print.
Mine was formatted for 1000 rows. The MSDN VBA object model website explains the switches used.
{DATABASE  \d "P:\\SourceDev\\Finacct\\PropNums_V14\\Data\\memodata.odc" \c "Provider=VFPOLEDB.1;Data Source=P:\\SourceDev\\Finacct\\PropNums_V14\\Data\\;Mode=Share Deny None;Extended Properties=\"\";User ID=\"\";Password=\"\";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE;DSN=\"\"" \s "SELECT * FROM `memodata`" \l "2" \*MergeFormat}
Please feel free to email me with questions, Chuck


>Is anyone having trouble with Word 2007 automation? I am using code from "Microsoft Office Automation with Visual Foxpro. I had no problems with Word2000 or Word2003. I print 2 memo's, one is a cover letter with addressee data inserted. The other inserts the same addressee data and inserts data about a data embedded query using another data source. As I said, this was working great until we upgraded to Office 2007.
>
>Now I am getting "Word cannot open document as a data or header source because it contains no data." after I have cleared old data. The next process, before the mailmerge execute, I open the headersource (works fine), then I open the datasource and get "File in Use, document is locked".
>
>No, no one else has the doc open, I checked WinExpl to find the doc closed but a reference to it with the "~" (weird). I have tried different Word objects using parameter 9 and 10, but no difference. Any ideas?
>
>Chuck
Extreme Programming = Plan -> Design -> Code -> Test
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform