title: Add corresponding OLE object (image) in table through button on form in MS Access
body: <p>I have a table Students with the following fields: Voornaam, Achternaam and Foto. The fields Voornaam and Achternaam are filled in with the students firstname and lastname. The field Foto (Picture) is empty. Because I don't want to manually add every picture of the students I wanted to do it with some code.</p>
  
  <p>I have a form where I put the records and I have a button to load the photos in the empty fields. I also have a textbox where I could say where he has to look for the photos.</p>
  
  <p>This is my code: </p>
  
  <blockquote>
    <p>Sub cmdLoad_Click()</p>
  
  <pre><code>Dim db As DAO.Database
  Dim rs As DAO.Recordset
  Dim query As String
  
  Dim MyFolder As String
  Dim MyPath As String
  Dim MyFile As String
  
  'On Error GoTo ErrorHandler
  
  Set db = CurrentDb
  query = "Select * FROM tblStudents"
  Set rs = db.OpenRecordset(query, dbOpenDynaset)
  
  MyFolder = Me!txtFolder
  
  'Wanneer er geen items zijn. Sluiten
  If rs.EOF Then Exit Sub
  
  With rs
      Do Until rs.EOF
          MyPath = MyFolder &amp; "\" &amp; [Voornaam] &amp; " " &amp; [Achternaam] &amp; ".jpg"
          MyFile = Dir(MyPath, vbNormal)
  
          rs.Edit
  
          [Foto].Class = "Paint.Picture"
          [Foto].OLETypeAllowed = acOLEEmbedded
          [Foto].SourceDoc = MyPath
          [Foto].Action = acOLECreateEmbed
  
          rs.Update
          rs.MoveNext
     Loop
  End With
  
  rs.Close
  db.Close
  Set rs = Nothing
  Set db = Nothing
  
  Exit Sub
  
  ErrorHandler:    MsgBox "Test Error #: " &amp; Err.Number &amp; vbCrLf &amp;
      vbCrLf &amp; Err.Description End Sub
  </code></pre>
  </blockquote>
  
  <p>I iterate on the results of the table. At every record I edit it and I want to add the picture to the foto field, but here's the problem.</p>
  
  <p>When I click the button to load in, I get the following error: </p>
  
  <blockquote>
    <p>a error occurred while microsoft access was communicating with the ole
    server or activex control
    . </p>
  </blockquote>
  
  <p>When I debug it's on this line where it goes wrong: </p>
  
  <blockquote>
    <p>[Foto].Action = acOLECreateEmbed</p>
  </blockquote>
  
  <p>I've tried to find a solution, but so far I couldn't find it. I hope the problem is a bit clear. Or is there a better solution?</p>