Linking word and access

  • Remove From My Forums
  • Question

  • I am having trouble linking MS Word to Access.  What I want to do is insert a field that has data from an access database and then allow an open connection so that if I update the database my word document is updated.

    I am trying to use the built-in tool in MS Word 2007 to select the database, define my query and then retrieve the information.  The problems I’m facing are:

    1. I go to Insert->Quick Parts ->Field -> Database -> Insert Database and define my database and query options.  On the third tab on the Query Options form, «Select Fields,» I select that I only want a single field.  Regardless
    of what I select however, it will always return ALL of the fields.  So even if the only thing in the «Selected Fields:» box is «ID» it will give me back every field in the record!

    2. If, when I press «Insert Data…» I press the «Insert data as field» check box, then I get the error: «Error has occured: Data type and mismatch in criteria expression.»  I have tried to use multiple databases but I
    always get this error.

    3. Ever since I installed the reference, «Microsoft ActiveX Data Objects 2.8 Library» I cannot run a recorded macro to insert a database record.  If I record a macro, insert a database without a live connection.  I can no longer run that
    SAME macro I just ran.  I get the «Data type and mismatch in criteria expression.» and a «word was unable to open the data source» error.

    For completeness my macro is:

       Selection.Range.InsertDatabase Format:=0, Style:=0, LinkToSource:=False, _
            Connection:= _
            «Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:Documents and Settingss384313DesktopSampledB.mdb;Mode=Read;Extended Properties=»»»»;Jet OLEDB:System database=»»»»;Jet
    OLEDB:Registry Path=»»»»;Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking» _
            , SQLStatement:= _
            «SELECT `ID`, `Name`, `Action`, `State` FROM `MCTDB` WHERE ((`ID` = ‘2’))» _
             & «», PasswordDocument:=»», PasswordTemplate:=»», WritePasswordDocument _
            :=»», WritePasswordTemplate:=»», DataSource:= _
            «C:Documents and Settingss384313DesktopSampledB.mdb», From:=-1, To:= _
            -1, IncludeFields:=True

    Thanks!

Answers

  • 1. Off the top of my head, try aliasing the table name. It shouldn’t be necessary, but Word can be picky.

            , SQLStatement:= _

            «SELECT [M].[ID], [M].[Name], [M].[Action], [M].[State] FROM [MCTDB] M WHERE (([M].[ID] = 2))» _

    (there’s no real difference between the « and the [] — but the [] always seem clearer to me).

    <<

    I have another problem that’s come up however:  It seems I cannot put these linked values inside of a table.  When I create an updating field and I put it in a table it gives me the error «Error! Not a valid result for a table.» 

    >>

    Unfortunately, the DATABASE field that is generated when you use Includefields:=True does not work inside another table.

    If you look at the current Word UI, you will see that the Database insertion facilities are not in the standard UI — in fact, they have not been there since Word 2003. Arguably, all the mechanisms for inserting data via field codes are now deprecated
    — I mean, you can use LINK fields to get stuff from Excel etc., but they don’t work in as useful way as they used to. The expectation now is that you use 3GL code such as C# or VB.NET to create documents by stuffing data in from outside. Crude, but that’s
    how it is.


    Peter Jamieson

    • Marked as answer by

      Wednesday, December 1, 2010 8:52 AM

Presentation on theme: «Integrating Word, Excel, and Access»— Presentation transcript:

1

Integrating Word, Excel, and Access

2

Objectives Integrate data among Word, Excel, and Access
Import an Excel worksheet into Access Copy a Word table to Access Link an Access table to Excel and Word Link an Access table to Word Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 2

3

Integrate Data Among Word, Excel, and Access
Integrating data from three programs Enter data into an Access database Make calculations using data in Excel Create Word report that includes Excel data and Access table Importing data from Excel spreadsheet into Access Copy a table from Word into a table in Access Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 3

4

Integrate Data Among Word, Excel, and Access
Importing Excel worksheet into Access Enter data directly into Access database table Import data from other sources Use Get External Data command Copying Word table into Access Copy and paste into new or existing table in Access Linking Access table to Excel and Word Keeps data current in all three applications Use Copy and Paste Special commands You cannot change structure of linked Access table in Excel Linking Access table to Word You can reformat the linked table in Word Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 4

5

Integrate Data Among Word, Excel, and Access
Excel data imported to an Access table Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 5

6

Integrate Data Among Word, Excel, and Access
Word report with links to Excel and Access Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 6

7

Import an Excel Worksheet into Access
Ways to import Excel data to Access Import Excel data into new Access table Append Excel data to an existing table Options in the Get External Data dialog box Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 7

8

Import an Excel Worksheet into Access
Changing a field name in an imported table Excel table imported to Access Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 8

9

Copy a Word Table to Access
Copy table in Word, Paste in Access Source Word table and destination Access table not linked Two methods for adding Word table Paste table into new, blank Access table Paste table into existing Access table Rule for pasting into existing table in Access Word and Access tables must have same number of records Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 9

10

Copy a Word Table to Access
Selecting the location for copied data Table containing data copied from Word Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 10

11

Copy a Word Table to Access
Renaming the ID field Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 11

12

Link an Access Table to Excel and Word
Benefits of linking three programs Reduce amount of data entry Use Copy and Paste Special commands Link Access object and Excel destination file Copy Excel data to Word file Changing data in source Access database Linked data in Excel and Word will update itself Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 12

13

Link an Access Table to Excel and Word
Copied data formatted in Excel Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 13

14

Link an Access Table to Excel and Word
Excel data pasted in Word Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 14

15

Link an Access Table to Excel and Word
Paste options Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 15

16

Link an Access Table to Word
Paste Access tables directly into Word if Excel is not needed Use Copy and Paste Special tools Data will link between Access and Word Access table can be formatted in Word Opening linked files and enabling content Open linked files in order of creation Broken links occur when linked files are moved to different locations Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 16

17

Link an Access Table to Word
Completed Word report Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 17

18

Link an Access Table to Word
Unit B integration tasks Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 18

19

Summary Integrating data among Word, Excel, and Access
Importing an Excel worksheet into Access Copying a Word table to Access Linking an Access table to Excel and Word Linking an Access table to Word Microsoft Office 2013-Illustrated Introductory, Windows 7 Edition 19

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Thanks. We have received your request and will respond promptly.

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It’s Free!

*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Linking Word Document and Access Data Entry Form

Linking Word Document and Access Data Entry Form

(OP)

14 May 03 14:36

Hi all — here’s what I need to do, but I’m not sure how to go about it.

I have a main data entry form where users enter bibliographic information.  I have a word document, already created, that’s in bibliography format.  

Is there a way to link the two so that when users enter new data into the form, the data updates the word document in the bibliography format?  I want to be able to print the word document in the bibliographic format with the new data from the form, as it gets updated from time to time.

Thanks — all input appreciated!

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join Tek-Tips® Today!

Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.

Here’s Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More…

Register now while it’s still free!

Already a member? Close this window and log in.

Join Us             Close

The example provided in that article is good but is specific to one
table. What you want to be able to do is create a solution for any
form. I am in the process of doing so however I ran into a snag.
That is being able to append a text control that contains carriage
returns for new lines. Word displays a little box and does not
provide a new line. Here is my current code undocumented. Hope it
helps:

Two procedures included:

This first one gets the bookmark name from a table which contains the
field name and word bookmark. Then the second pages thru the
recordset and sets the field equal to the data in the table.

Public Function GetBookMark(FieldName As String) As String
‘GetBookMark(«Detailed_Disposition_W51»)
‘purpose: to get word bookmark for pasting data to word doc

Dim dbs As Database
Dim strSQL As String
Dim rst As DAO.Recordset

strSQL = «SELECT BookMarks.FieldName, BookMarks.BookMark FROM
BookMarks WHERE (((BookMarks.FieldName)='» & FieldName & «‘));»
‘strSQL = «SELECT BookMarks.* FROM BookMarks;»
‘CreateAndRunActionQuery (strSQL)

Set dbs = CurrentDb ‘Point to current database
Set rst = dbs.OpenRecordset(strSQL) ‘open recordset

If Not rst.EOF Then
GetBookMark = rst![Bookmark] ‘Return record set
End If
Chr (13)

End Function
Public Function writeword1()

Dim strSQL As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim fld As DAO.Field
Dim FieldName As String
Dim FieldValue As String
Dim BookMarkName As String
Dim objWord As Word.Application

Set objWord = CreateObject(«Word.Application»)
objWord.Visible = True ‘Show Word.
objWord.Documents.Open («C:Documents and
SettingsJulieDesktopRCI_Template2.doc») ‘Open the document.

strSQL = «SELECT tbl_RCI1.* FROM tbl_RCI1;»
Set dbs = CurrentDb ‘Point to xcurrent database
Set rst = dbs.OpenRecordset(strSQL) ‘open recordset

For Each fld In rst.Fields
FieldName = fld.Name
If FieldName <> «ID» Then
If Not IsNull(fld.Value) Then
FieldValue = fld.Value
BookMarkName = GetBookMark(FieldName)
objWord.ActiveDocument.Bookmarks(BookMarkName).Select ‘Move to
each bookmark and insert text.
‘ objWord.ActiveDocument.FormFields.Shaded = Not
ActiveDocument.FormFields.Shaded
If BookMarkName Like «*check*» Then
If FieldValue = «true» Then
objWord.ActiveDocument.FormFields(BookMarkName).CheckBox.Default
= True
Else
objWord.ActiveDocument.FormFields(BookMarkName).CheckBox.Default
= False
End If
Else
objWord.ActiveDocument.FormFields(BookMarkName).Result =
FieldValue
‘if you find new line char then grab first part of text and
line character then
‘ set form field
End If
End If
End If
‘Call Write2Word(BookMarkName, FieldValue)
Next fld

‘Close the document without saving changes.
‘ objWord.ActiveDocument.FormFields.Shaded = Not
ActiveDocument.FormFields.Shaded
objWord.ActiveDocument.SaveAs FileName:=»C:Documents and
SettingsmjDesktopDoc1.doc»
‘Quit Microsoft Word and release the object variable.
‘ objWord.Quit

Set rst = Nothing
Set fld = Nothing

‘rst.Close
Set db = Nothing
Set objWord = Nothing

End Function

  • Remove From My Forums
  • Question

  • Hello all,

    I am working on a book that covers the Procert labs Word Expert 2010 objectives and can’t figure out objective 5.3.3 which is written, «Link a form to a database.»

    I have rigorously searched the internet for any clues, and the only thing I came up with was using VB code or XML code to accomplish this task. To me, that is way above what should be covered in the expert objectives, which leads me to believe that there
    is an easier way to do it. If anyone has any ideas I would be very appreciative if you shared them : )

    Also, I have searched these forums for anything related to this objective and failed to find an answer.

Answers

  • It cannot be done without programming.  If you want that, you should use an Access form.

    If you want to do it with a form in Word, see the last of the following series of articles:

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

    Please Fill Out This Form
    Part 1: Create professional looking forms in Word
    http://www.computorcompanion.com/LPMArticle.asp?ID=22

    Part 2: Adding Automation to your Word forms.
    http://www.computorcompanion.com/LPMArticle.asp?ID=46

    Part 3: Learn more VBA (macros) to automate your forms.
    http://www.computorcompanion.com/LPMArticle.asp?ID=119

    Part 4: Use custom dialog boxes in your Word forms
    http://www.computorcompanion.com/LPMArticle.asp?ID=127

    Part 5: Connect your AutoForm to a database to save input time and keep
    better records!
    http://www.computorcompanion.com/LPMArticle.asp?ID=136

    — Hope this helps.

    Doug Robbins — Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    «Ian Rutkosky» wrote in message news:c90972df-69b8-436e-863a-0e8a563e549f@communitybridge.codeplex.com…

    Doug,

    Thanks for the assistance, but I guess I need to clarify what I am looking for in more detail. This is what I am thinking the objective wants:

    1. Make a Form using Word

    2. Link that Form in Word to an Access database — meaning what the person enters in the word form will populate an access database table

        aka…    Word —-> Access     not      Access —-> Word

    3. There should NOT be any programming involved in this process… people using word should NOT be expected to write programming code to complete this objective.

    The full objective is listed as follows:

    5.3. Create Forms

          5.3.1 Use the Controls group

          5.3.2 Add Help content to form fields

          5.3.3 Link a form to a database

          5.3.4 Lock a form

    So, I can do all of them but 5.3.3.

    Again thanks for the help and thanks in advance for future help!

    Ian Rutkosky


    Doug Robbins — Word MVP dkr[atsymbol]mvps[dot]org

    • Marked as answer by

      Thursday, October 28, 2010 6:38 AM

Понравилась статья? Поделить с друзьями:
  • Linking verb example word
  • Linking value in excel
  • Linking text in excel
  • Linking tables to text in word
  • Linking pictures in word