ACC97: How to Merge Pictures and Text from an Access Table with a Word Document Without Having to Store the Pictures

ID: Q219054


The information in this article applies to:
  • Microsoft Access 97

Moderate: Requires basic macro, coding, and interoperability skills.


SUMMARY

When you follow the usual procedures for merging a Microsoft Access table with a Microsoft Word document, the pictures that are stored in the Access table are not successfully merged into the Word document.


MORE INFORMATION

The following code sample demonstrates how to create a new Word document and how to merge the text from one field next to a picture taken from a text field in the Access table. The text field will contain only the path to the picture on the hard disk.

  1. Open an Access database and create a new table named Sample.


  2. Add two text fields to the table as follows:


  3. Field name Data type Field size
    Description Text 50
    Picture Text 100
  4. Search your hard disk for files with the extension .jpg and populate the Samples table with several new records. Include a description that describes the picture, and the full path to the picture on the hard disk, for example:


  5. Description = "One Hundred"
    Picture = "C:\Program Files\Microsoft Office\Templates\Access\100.jpg"
  6. Type the following function into a new module:


  7. 
    Option Compare Database
    Option Explicit
    
    Public Function Merg()
        Dim obj As Object
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
    
        Set db = CurrentDb
        Set rs = db.OpenRecordset("Sample")
        Set obj = CreateObject("Word.Application")
    
        obj.Application.Visible = True
    
        rs.MoveFirst
    
        'The following line assumes Word's Normal template is in the default
        'location.
        obj.Documents.Add Template:="C:\Program Files\Microsoft _
           Office\Templates\Normal.dot", NewTemplate:=False
    
        Do While Not rs.EOF
            With obj
              .Selection.TypeText Text:="" & rs![Description]
              .Selection.InlineShapes.AddPicture FileName:="" & rs![Picture], _
                  LinkToFile:=False, SaveWithDocument:=True
              .Selection.TypeText Text:=Chr(13)    'New Line.
              .Selection.InsertBreak Type:=3       'wdSectionBreakContinuous.
            End With
            rs.MoveNext
        Loop
    End Function 
  8. Type the following line in the Immediate window, and then press ENTER:


  9. 
    ?Merg() 


REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

Q131583 Sending the Current Record to Word 97 with Automation
Q114306 Inserting Database in Word Document Does Not Retain Pictures

Additional query words: inf howto

Keywords : kbdta
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: January 27, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.