Viewing Access Tables in Word with VBA or VBA.Net

R

Robert Taylor

Can anybody tell me how I can link word, using VBA or
VBA.net, to an Access database so that I can retrieve
data from an Access Table into a word document. I am
trying to creat a document assembly program and I have
several hundred clauses in an Access Database that I want
to use. Many thanks
 
C

Cindy M -WordMVP-

Hi Robert,
Can anybody tell me how I can link word, using VBA or
VBA.net, to an Access database so that I can retrieve
data from an Access Table into a word document. I am
trying to creat a document assembly program and I have
several hundred clauses in an Access Database that I want
to use
I'm not sure whether you mean you want to import the tables,
directly, or generate them "cell by cell" using something
like ADO(.NET)?

Assuming the former, what you probably want to use is the
DATABASE field. In the UI, display the Database toolbar and
use the Insert Database button. Even though you want to
automate this, I recommend you "play with it" a bit in the
UI to understand what's going on.

Using Alt+F9 you can view the Field Code that's generated
when, in the last step, you activate the checkbox to insert
as a field. This is a dynamic link back to the data table or
query.

the content of the database field is the kind of information
you'll need to dynamically bring database tables into a Word
doc. The switches (\+letter) control various aspects of the
connection. You can find out what they do by searching
"Database field" in Word's Help files.

Note that you do NOT want to try using the InsertDatabase
method in the Word object model. While this looks like it
will do exactly what you need, in practice it's not
reliable. Instead, you should take the field text content
and use it in the TEXT argument for the Fields.Add method.

Something else we may need to discuss is what connection
method (DDE, ODBC, OLEDB) should be used. I'd need to know
which versions of Word we'd be dealing with, however. As a
general rule of thumb, you're best off with ODBC, though.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top