I have a VFP form where the user can print the invoices for a batch of client. Each invoice can be preceded by a cover letter written in Word by the user. The printout is done on a multiple bins printer.
Here's the logic:
- Create the cursor for the cover letters - Create the cursor for the invoices - Create the mail merge in Word: - Open an instance of Word - Open the letter - Set the data source (ODBC VFP) - Start the mail merge - For each invoice: - Set the printer bin to the cover letter paper - Go to page n in Word - Select the page - Print the page - Set the printer bin to the invoice paper - Print the invoice
The result is a printout where no assembly is necessary since the cover letter and the invoice for each client are printed togheter.
This was working well for the past year or so, but now we are facing with a major problem. When printing more that 1,000 invoices, Word seem to choke and the process slow to a crawl until Word crash in the end with a "Not enough space" error message. In the task manager, I see the Word process taking around 25% of the CPU (still OK), but the memory consumption grow over 800MB before crashing. It take around 3 or 4 minutes to print a page.
I've done tests with Vista and Word 2007 and with XP and Word 2003 and both give the same result.
Here's the time it take to complete the process:
- 100 invoices -> 0:02:14 - 1,000 invoices -> 1:31:41 (should have taken around 20 minutes) - 2,000 invoices -> Word crash
The solution I see would be to break down the merge process in batches of 100 records instead of a single batch, but it will require changes in the system that I would like to avoid.
Anyone have an idea of why this process won't work anymore? Any testing I should do to locate and fix the problem?
Update: I found the culprit to my slowdown. Since there were 2 calculated fields (a date and a hyperlink), Word was refreshing all the fields in all the pages of the document each time I asked to print a page. I removed the calculated fields from the Word document and everything is back to normal.