I currently have a form in MSAccesss that gets users to attach any relevant documents and a script that runs an automation of populating data from Access into a Word Template.
The code that I have is not being flagged down as a bug or has any compiling errors, however, the attachment does not seem to be appearing on the generated word document.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'create a new instance of word if not opened
Set appWord = CreateObject("Word.Application")
End If
Dim doc As Word.Document
Set doc = Documents.Add(CurrentProject.Path & "\BCPPrototype_Template.dotm")
Dim rsa As DAO.Recordset
Set rsa = CurrentDb.OpenRecordset("heh_attachment")
If rsa.RecordCount > 0 Then
doc.Bookmarks("call_tree").Range.InsertFile (CurrentProject.Path & "\" & rsa!FileName)
End If
Set doc = Nothing
rsa.close
set rsa = nothing
end sub
Edit:
Implementing what was suggested below, current code is
Dim rsa As DAO.Recordset2, fd As DAO.Field2
Set rsa = CurrentDb.OpenRecordset("SELECT AttachmentFieldName FROM TableName")
Set fd = rsa("AttachmentFieldName")
fd("FileData").SaveToFile CurrentProject.Path
If rsa.RecordCount > 0 Then
doc.Bookmarks("call_tree").Range.InsertFile (CurrentProject.Path & "\" & rsa!FileName)
end if
but the file simply isn't appearing. I tried to comment the code to save the file and manually save it in the same folder too, same issue of file attachment not appearing occurs. I also tried without the bookmark and simply referring to the cell range, same issue occurs.
ideally, what I am trying to accomplish is that, by inserting the file attachment in generated word document. I can access the file from the generated word document by clicking on it.
If Not rsa.EOF Then
.