473,513 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS Word Drop-Down List with MS Access Data

18 New Member
I've found a few threads (not specifically on this site) doing what I'm attempting, but none work in 2007 or later versions.

I have a MS Word Form with a Drop-Down List (Legacy Control) with a list of employee names. Each time a change in employees occurs, I have to go change this form. I'd like the drop-down list to update the available options upon opening, based on information in an Access DB. I have future intentions of improving on this concept on another form which I'd like to fill in other text fields on the Word Form based on the value selected from the first dropdown.

I'm comfortable with VBA, but can't figure this one out. I wish I could just recreate these forms in Access (report), but they belong to another agency.

I have both Word and Access in versions 2010 and 2013. The back-end that I'm wanting to work with data in is in .mdb format.

Here's a link to a thread that was apparently successful in earlier versions of MS Office: http://www.techrepublic.com/blog/how-do-i/how-do-i-dynamically-fill-microsoft-word-fields-using-access-data/

Here's the code from the above mentioned thread:
On "This Document"
Expand|Select|Wrap|Line Numbers
  1. Private Sub Document_Open()
  2. 'Populate employee dropdown field.
  3.     Dim db As DAO.Database
  4.     Dim rst As DAO.Recordset
  5.     Dim strSQL As String
  6.     Dim strPath As String
  7.     Dim doc As Document
  8.         Set doc = ThisDocument
  9.             strSQL = "SELECT LastName FROM Employees ORDER BY LastName"
  10.             strPath = "H:\SPD\" _
  11.                 & "Northwind 2007 sample.mdb"
  12. 'Update path to database file.
  13.         Set db = OpenDatabase(strPath)
  14.         Set rst = db.OpenRecordset(strSQL)
  15.             Do While Not rst.EOF
  16.                 With doc.FormFields("wfLastName").DropDown.ListEntries
  17.                     .Add Name:=rst(0)
  18.                 End With
  19.                     rst.MoveNext
  20.             Loop
  21.         Set db = Nothing
  22.         Set rst = Nothing
  23. End Sub
  24.  
This is on the Module:

Expand|Select|Wrap|Line Numbers
  1. Sub FillDependentFields()
  2. 'Fill form fields based on selected employee
  3. 'in wfEmployeeDropdown.
  4.     Dim db As DAO.Database
  5.     Dim rst As DAO.Recordset
  6.     Dim doc As Document
  7.     Dim strSQL As String
  8.     Dim strPath As String
  9.         Set doc = ThisDocument
  10.             strSQL = "SELECT TitleOfCourtesy, FirstName FROM Employees " _
  11.                 & "WHERE LastName = '" _
  12.                 & doc.FormFields("wfLastName").Result _
  13.                 & "'"
  14.             strPath = "C:Program FilesMicrosoft Office11OFFICE11SAMPLESNorthwind.mdb"
  15.         Set db = OpenDatabase(strPath)
  16.         Set rst = db.OpenRecordset(strSQL)
  17. 'Ignore Null values from Access data.
  18. On Error Resume Next
  19.             doc.FormFields("wfTitleOfCourtesy").Result = rst(0).Value
  20.             doc.FormFields("wfFirstName").Result = rst(1).Value
  21.         Set db = Nothing
  22.         Set rst = Nothing
  23. End Sub
  24.  
  25. Private Sub Document_Close()
  26. 'Clear  fields.
  27.     Dim doc As Document
  28.         Set doc = ThisDocument
  29.             doc.FormFields("wfLastName").DropDown.ListEntries.Clear
  30.             doc.FormFields("wfFirstName").TextInput.Clear
  31.             doc.FormFields("wfTitleOfCourtesy").TextInput.Clear
  32. 'Close without saving or prompting.
  33.     ActiveDocument.Saved = True
  34.         Set rst = Nothing
  35. End Sub
  36.  
I've set the reference library "Microsoft DAO 3.6 Object Library." I have the Northwind Sample DB where I'm first trying to prove functionality before applying to my actual records (in .mdb format). I get an error upon opening my word form (actually it's a blank word doc, with macros enabled): Run-Time error '3343': Unrecognized database format 'H:\SPD\Northwind 2007 sample.mbd'." Debug brings me to line #13 of the first listed section of code (also shown below):

Expand|Select|Wrap|Line Numbers
  1.         Set db = OpenDatabase(strPath)
  2.  
The path listed is a valid path. I've tried using "Microsoft Office 14.0 Access Database Engine Object Library" and changed DB format to .accdb, and every combination of these with similar results.
Oct 13 '16 #1
0 1005

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2699
by: t.kiesche | last post by:
Hello I want to make a textfield (INPUT type=text) or something that looklike this, to drop down a list with word. Just like: A user writes the letter 'a' and in the dropdown list come a list of word starting with 'a'.
3
7064
by: Charles | last post by:
I am trying to add the ability for a user to change the order in which the elements are listed in a dropdown list box. Before I added the ListID field the dropdown list box order was controlled using the MotorhomeID. The problem I am having is that I don't know the best method for allowing people to make the ListID changes easily. ...
1
1351
by: bbdobuddy | last post by:
Hi, I have a connection to a SQL database. One of the tables in the SQL Database is DefendentInformation. I would like to get the firstName and lastName fields from that table combine them and add that as a value to the drop down list. However, I don't know what to put in for the datasource property.
11
7360
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and the Dropdown doesnt have any items.. The requirement is that as soon as one goes on typing the letters in the StudentName-textbox the corresponding...
3
1352
by: sandesh964 | last post by:
can i get the code for inserting a word document into access data base and retrieve it from the data base i am using asp.net with c#
1
1848
by: fran7 | last post by:
Hi, Anyone know how to populate a dropdown list with data from database. I have an interface that generates the following code for names in my database. ..asp <%If Trim(rsCard("Author"))<>"" Then%> <%=rsCard("Author")%><%End If%> .. How does one populate a dropdown list??
3
5749
by: ashokkuncha | last post by:
hi all, i am new bee and hope some one help me out. in my web application i am using access as data base, one table of the dabase has candidates details as records ( emp no, name , skill set ect ). now i need to add new column ' Resume' that will have resumes(word files) of the candidates as column values. i should be able to...
5
6640
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access database. in second dropdown list i want to get data according to selection made in first dropdown list and it will also come from ms-access database.(for example if i am selecting country as india in...
8
1459
by: sophannaly | last post by:
Hi, I have a problem with dropdown list in combo box. Combo box row source returns 3 fields data likes revision, type, description. In these 3 fields, only revision may have duplicate number but type number is different. Bound column of this combo box is revision. Column count is 3 and width is 0,0,2. I need to show only description of that...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.