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:
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:
Field name |
Data type |
Field size |
Description |
Text |
50 |
Picture |
Text |
100 |
- 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()
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