开发者

How to communicate ms word and ms access in vb.net?

I want to create a program th开发者_如何学Pythonat could generate reports from an ms access database and place it on ms word, how can I do that. Please help, I dont have any idea on how to do this.


If you're doing this from vb.net, it seems to me that it would be simpler to automate Word, which has no difficulty utilizing Jet/ACE data as data source. I don't see any reason to involve the Access application in this, unless you have complex logic that needs to be executed within Access to get correct results in Word. For instance, Word doesn't do parent/child data display very well, but Access reports do that very easily.

Another question is the final disposition of the results. It may be that you don't need Word at all, e.g., if you're using Word for nothing more than generating PDFs. In that case, it might make more sense to create Access reports and output those to PDF (there's an add-in available for for A2007, and in previous versions, you can use the VB automatable PDFCreator, which is free).

In short, my conclusions would be:

  1. if you're just merging data in Word from a Jet/ACE data store, then automate Word.

  2. if you need to execute complex logic, it's probably better to automate Access and either output Access reports directly, or automate Word from Access.

In neither case, I believe, would you be automating both Word and Access directly from your VB.NET application.


You should connect to the Access Database using a Typed Dataset.

Right-click the project, click Add New Item, select Typed Dataset, and follow the wizard.

To control Word, add a reference to Microsoft.Office.Word and use the Application class.


You can build reports in MS Access that have the Export to Word functionality built into them.

You can invoke the report from your code and then call the export functionality and give it parameters so that it will export to a .doc file that you name. You can then invoke MS Word and open the .doc file up for display.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜