Document Management from Word and Access using VBA (Office XP)

  • Thread starter jojo the clownfaced warthog
  • Start date
J

jojo the clownfaced warthog

I've got a document consisting of several chapters, each of
which have been broken out into their own document.

I've got an access database, listing customers and the
chapters they are to be provided.

What I -don't- have (and can't seem to find anywhere, having
tried in vain at MS's site and a hundred different programming
sites) is a way to query the database from within Word.

I have two tables, Customers and CustomerChapters (actually
I have more, but these two will do for now).

Customers contains:

1. CustomerID
2. CustomerName

CustomerChapters contains:

1. CustomerChapterID
2. CustomerID
3. ChapterID
4. OrderOfAppearance

What I want to do:

1. Query the Customers table for all customer names.
2. Present all customers in a pop-up window with a
drop-down list. (steps 1 and 2 are optional; I could
just type in the customer ID in the macro, but we're
dreaming big, here :eek:) ).
3. Query the Customers table for all chapter IDs
belonging to the selected (or specified) CustomerID.
4. Retrieve the first word doc identified by the retrieve
in step 3 (as arranged by OrderofAppearance).
5. Append the next word doc, and the next, 'til the end.

I know the SQL code, so that's not too much of a problem.
What I need (long time to come to a point, huh? :eek:) ) help
with is the VBA code, particularly for steps 3 and 4.

Can anyone help?

Thanks!

-Jon
 
M

martinique

Coding this from VBA is exactly the same as coding it from VB, and you'll
surely have no trouble finding examples on any of the VB code sites or even
just the companion database forums.

It's a bit too big a question to answer in detail, but in essence:

1. Add to your VBA project a reference to the database technology you want
to use: DAO or ADO.

2. Establish a connection to the database. With DAO you simply instantiate
the database object and open it; with ADO you create a Connection object.

3. Run your SQL queries to retrieve and/or update your data.

4. Close everything. (Word doesn't care, but your database might)
 
J

jojo the clownfaced warthog

Coding this from VBA is exactly the same as coding it from VB, and you'll
surely have no trouble finding examples on any of the VB code sites or even
just the companion database forums.

It's a bit too big a question to answer in detail, but in essence:

1. Add to your VBA project a reference to the database technology you want
to use: DAO or ADO.

That was the hint I needed. Working happily now. Thanks!

-j
 

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