Microsoft KB Archive/219054

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

Article ID: 219054

Article Last Modified on 1/24/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q219054



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.  Open an Access database and create a new table named Sample. Add two text fields to the table as follows:  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:

Description = "One Hundred"

Picture = "C:\Program Files\Microsoft Office\Templates\Access\100.jpg"

  Type the following function into a new module: 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   Type the following line in the Immediate window, and then press ENTER: ?Merg 

<div class="references_section">