WORD Automation: Apparent Timing Problems
Posted on 2006-04-27
I have a VB6 app that builds a WORD doc from an Access database. Usually it works fine, but sometimes -- apparently because of timing considerations -- it does not. When it fails, it fails because the sequence of items that appears in the generated WORD doc does not reflect the sequence in which these items are generated in the VB6 app -- apparently asynchronism associated with automation is biting me. In these failure situations, the order of the data being generated by the VB app is not the order in which the data is being accepted by WORD. For example, elements from the n+1 record in Access will sometimes appear in WORD before elements of the n record.
By sprinkling DoEvents -- either standalone or within a FOR LOOP -- at places within the VB6 app, I've eventually been able to get the app to work much more reliably, but I'm not at all sure that I've handled all likely timing glitches.
Indeed, I don't understand why the problem exists even without the DoEvents. I would expect that WORD receives all the msgs from my VB6 app via a single ordered queue, so how are things sometimes getting out of order? Am I missing something?
Any ideas what is happening and what's required to fix it?