title: how to insert picture into word doc from access database using vba
body: <p>I'm trying to read picture from access attachment field and then insert it into word document. As the below code show, I could read an attachment into a file and then insert it to word doc but it's inefficient and I want a way to directly do this. any idea?</p>
  
  <pre><code>Option Compare Database
  
  Sub picloader()
  
      Dim appword As Word.Application
      Dim doc As Word.Document
  
      On Error Resume Next
      Err.Clear
  
      Set appword = GetObject(, "Word.Application")
      If Err.Number &lt;&gt; 0 Then
          Set appword = New Word.Application
  
      End If
  
      appword.Visible = True
      appword.Activate
  
      'word doc to save picture
      Set doc1 = appword.Documents.Open("D:\file1.docx")
  
  
      Dim db As Database
      Set db = CurrentDb
  
      Dim picpath As String
      Dim people As String
      Dim rspictures As Variant
  
      'Dim tmp As Variant
  
      picpath = "D:\file1.jpg"
  
      Dim rs As DAO.Recordset
  
      people = "select * from persons"
      Set rs = CurrentDb.OpenRecordset(people)
  
      If Not (rs.EOF And rs.BOF) Then
          rs.MoveFirst
  
          Set rspictures = rs.Fields("Picture").Value
  
             While Not rspictures.EOF
                  rspictures.Fields("FileData").SaveToFile (picpath)
  
                  rspictures.MoveNext
             Wend
      End If
  
      Dim wrdPic As Word.InlineShape
  
      Set wrdPic = doc1.Bookmarks("picture").Range.InlineShapes.AddPicture(picpath, LinkToFile:=False, SaveWithDocument:=True)
  
               wrdPic.ScaleHeight = 10
               wrdPic.ScaleWidth = 10
  
  
      Exit Sub
      errHandler:
      MsgBox Err.Number &amp; ": " &amp; Err.Description
  
      End Sub
  </code></pre>