Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

populating combo box in a form created in vba in word from an access database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pat933@gmail.com - 16 Apr 2007 00:51 GMT
Hi there,
I need to populate the contents of a dropdown combo box in a form
which i have made in word 2003 using vba from an access database. i
need to know the code for establishing connectivity between the two,
as well as where to insert this code in.
Cheers,
Pats.
Perry - 16 Apr 2007 18:03 GMT
Here's some code from Word VBA, in a userform code module
hosting a listbox (Listbox1) getting populated by an MS Access table.

Dim cn as new ADODB.connection
   Dim rs as new ADODb.recordset
   cn.connectionstring = _
   "Provider=Microsoft.Jet.oledb.4.0;" & _
   "Data Source=d:\data\access\mydatabase.mdb;"

   cn.open

   rs.open "select * from tblMyTable", cn

   If rs.recordcount < 1 then
       Msgbox "No records"
   Else
       'This is your Word VBA listbox
       Me.listbox1.columncount = rs.fields.count
       me.listbox1.column = rs.getrows(rs.recordcount)
   End if

   rs.close: set rs = nothing
   cn.close: set cn = nothing

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE

> Hi there,
> I need to populate the contents of a dropdown combo box in a form
[quoted text clipped - 3 lines]
> Cheers,
> Pats.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.