chacham
Member
- Local time
- Today, 01:56
- 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.
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?
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: