Simple VBA data link code?

M

Marc

With Office 2003, I would like to have a combobox that pulls information from
either access or excel but I can't find an easy way to do this. Let me pose
this with an example.

Word 2003 document "c:/templates/fruits.dot"
Userform1 has 1 combobox on it with a drop-down list of 3 items:
Oranges, Apples and Pears.

Access Database 2003 "c:/fruits.mdb"
fruits.mdb
Table with data is Table1

How would I code in VBA, in my word template so that when a user selects
Apples from the combobox the description from the table will display in the
word document where I have a bookmark [.] for fruit?

I can't find any information, anywhere, on doing this. Thank you for any
help or suggestions you are able to give me.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TWFyYw==?=,

There's no way to actually make a LINK to the data. That's really only possible
within Access, or with built-in tools in languages such as classic VB and .NET,
that take care of the data linking for you, behind the scenes.

In Office 2003, you have to do all the coding yourself. That means, you'd have
an event in the combobox set up a connection to the database and perform the SQL
necessary to retrieve the information. The code would then put this into the
bookmark location.

I think you'll find a sample on how this can work in the WdAcc97.zip file on my
website; Mail merge FAQ, Special Merges section. It may not have an example that
does exactly what you're asking for, but all the pieces are in there. Even
though it was written years ago for Office 97, the basic approach will still
work in Office 2003.
With Office 2003, I would like to have a combobox that pulls information from
either access or excel but I can't find an easy way to do this. Let me pose
this with an example.

Word 2003 document "c:/templates/fruits.dot"
Userform1 has 1 combobox on it with a drop-down list of 3 items:
Oranges, Apples and Pears.

Access Database 2003 "c:/fruits.mdb"
fruits.mdb
Table with data is Table1

How would I code in VBA, in my word template so that when a user selects
Apples from the combobox the description from the table will display in the
word document where I have a bookmark [.] for fruit?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

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