Linking an access database to a combo(list) box in word.

T

Timjohn

I have an access database holding many records and I would like to create a
combo or list box in word so that whilst creating a document I can scroll
down the database via an on screen combo(list) box and choose items to be
inserted into the word document. I have tried vb in word macros but don't
seem to have a data source property on the combo boxes or list boxes. Any
help or suggestions gratefully recieved.
 
D

Dian D. Chapman, MVP

I do this Word/DB connectivity stuff all the time (see samples:
http://www.mousetrax.com/Consulting_Solutions.html).

What you need to do first is setup an ADO connection (ActiveX Data
Object). Once you have the connection, then you can query the DB with
SQL to create a RecordSet. From there, you simply use that RS to pull
or populate whatever you want to/from Word <--> Access/SQL DBs.

I have a sample on my web site with open code so you can see how to
create the ADO link...the code will get you started. It's fairly
elementary code to help newbies understand it.

Go here:
http://www.mousetrax.com/techpage.html#autoforms

Read the PLEASE FILL OUT THIS FORM article marked as # 5 for Database
Connectivity. Download the associated sample zip file. There you'll
find a sample Word AutoForm with sample Access DB to show you how to
create the connection to open a ADO "tunnel" between the two..

To actually populate the ListBox, you'll just need to write a loop
that inserts the first record in the set as you want it...and
continues to loop through the DB using... Do Until RS.EOF (do until
end of record set) to continue adding each record. If you want them
all...you'd query with SELECT * FROM MyTable to give you the entire DB
list. This stuff gets added to your form's initialization event.

Have fun! ;-)

Dian D. Chapman
Technical Consultant, Microsoft MVP
MOS Certified, Editor/TechTrax

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
 
T

Timjohn

Thanks Dian,

I'll give it a look tomorrow, very glad its for newbies though!

I'll let you know how I get on.
Regards,
Tim
 
D

Dian D. Chapman, MVP

No problem. Good luck with it. And if you need further help with it
and I seem to be missing this thread in the future, feel free to jump
into my group here: http://tech.groups.yahoo.com/group/Word_VBA/ as
I'm in there much more often.

Dian D. Chapman
Technical Consultant, Microsoft MVP
MOS Certified, Editor/TechTrax

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
 

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