Solved Trying to add a png to an OLE Object column in code, fails with Run-time error '13146' (1 Viewer)

chacham

Member
Local time
Today, 02:29
Joined
Oct 26, 2020
Messages
45
Converting an attachment field to an OLE column (in a child table) via code works fine unless the attachment is png.

Code:
Sub b(Table As String, PK As String, Column As String, Form As String, FK As String, Field As String)
            Dim Recordset As DAO.Recordset2
            Dim Attachments As DAO.Recordset2
          
            DoCmd.OpenForm Form
          
            ' Loop through table
            Set Recordset = CurrentDb.OpenRecordset(Table)
            Do While Not Recordset.EOF
          
                ' Loop through attachments
                Set Attachments = Recordset(Column).Value
                Do While Not Attachments.EOF
              
                    Attachments("FileData").SaveToFile CurrentProject.Path
      
                    ' Add attachment to the form
                    Forms(Form).Controls(FK) = Recordset(PK)
          
                    With Forms(Form).Controls(Field)
                        .SourceDoc = CurrentProject.Path & "\" & Attachments("FileName")
                        .Action = acOLECreateEmbed
                    End With
                  
                    DoCmd.RunCommand acCmdRecordsGoToNew
                    Kill CurrentProject.Path & "\" & Attachments("FileName")
                
                    Attachments.MoveNext
                Loop
      
                Recordset.MoveNext
            Loop
          
            ' Cleanup
            Recordset.Close
            Set Recordset = Nothing
        End Sub



Clicking Debug, it highlights `.Action = acOLECreateEmdbed`. Checking, the file <filename>.png exists.

Attaching the file manually, either through the table or via form, works just fine. Is there a way to do this in code?
 
Last edited:

chacham

Member
Local time
Today, 02:29
Joined
Oct 26, 2020
Messages
45
Okay, someone answered the problem for me elsewhere. Png is not an embeddable type, hence acOLECreateEmbed is the wrong action, and instead should be linked via acOLECreateLink.
 

Users who are viewing this thread

Top Bottom