none
Transfer of attachments to Word RRS feed

  • Question

  • Hi all,

    In a database, the user inserts an attachment which is stored in a table, along with some data entered by the user. I then "export" the data to a Word document using bookmarks. This is for reporting purposes only.

    All is running fine with no issues. My question, however, is this:

    Is it possible to "export" the linked attachment in the Access table to the Word document?

    Much appreciated

    Deon

    Thursday, August 24, 2017 6:04 AM

Answers

  • Hi all,

    I have found the solution:

    If I use .Item("CurriculumLink_Line" & i).Range.Text = rst.Fields("Attachment_C.FileName"), The filename is inserted into the Word document.

    Thanks for your assistance.

    Regards

    Deon

    • Proposed as answer by Chenchen LiModerator Friday, August 25, 2017 7:38 AM
    • Marked as answer by Deon SA Friday, August 25, 2017 7:46 AM
    Friday, August 25, 2017 6:39 AM

All replies

  • Assuming you are using Word automation, the linked attachment would need to be saved to a file before you could embed or link into a Word document. The implementation of the Attachment field type is specific to Microsoft Access and not compatible with other Office apps or DBMS.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, August 24, 2017 4:24 PM
  • Hello,

    What do you mean "linked attachment"?

    If the files are in the attachment field, I think they are actually embedded in the table or database. There is no link between the field and the original file.

    If you are using Hyperlink field, you may export the data and check if it is hyperlink using TextBox.IsHyperlink Property (Access). You could add hyperlinks in Word document using Hyperlinks.Add Method (Word) after retrieving hyperlink address in Access. According to Hyperlink.Address Property (Access) and Label.HyperlinkAddress Property (Access), the HyperlinkAddress property can contain an absolute or a relative path to a target document. If it is relative path, you may use CurrentProject.Path or the code below to get the hyperlink base.

    Sub getHyperlinkBase()
    Dim hyperlinkBase As String
     Dim dbs As DAO.Database, cnt As DAO.Container
      Dim doc As DAO.Document, prp As DAO.Property
       Set dbs = CurrentDb
       Set cnt = dbs.Containers!Databases
      Set doc = cnt.Documents!SummaryInfo
     doc.Properties.Refresh
     Const conPropertyNotFound = 3270
      On Error GoTo Err
     hyperlinkBase = doc.Properties("Hyperlink base").Value
    Err:
    If Err = conPropertyNotFound Then hyperlinkBase = "None"
    Debug.Print hyperlinkBase
    End Sub

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 25, 2017 3:42 AM
    Moderator
  • Hi,

    Thanks for the response. Yes, the attachments are embedded in the table. I tried using the following code, but I get erros that the item is not found in the collection:

        Sql1 = "SELECT Tbl_All_Attachments_Curriculum.[AttachmentCourseNumber_C], Tbl_All_Attachments_Curriculum.[Attachment_C], Tbl_All_Attachments_Curriculum.[Attachment_C].[FileData], Tbl_All_Attachments_Curriculum.[Attachment_C].[FileName], Tbl_All_Attachments_Curriculum.[Attachment_C].[FileType], Tbl_All_Attachments_Curriculum.[AttachmentParagraph_C] " _
            & "FROM Tbl_All_Attachments_Curriculum WHERE AttachmentCourseNumber_C = " & Val(Forms!Frm_GeneralReporting.Text0) & ";"

    The statement is executed, but when I use the following to "export" to Word, an error occurs:

        For i = 1 To 5
            .Item("CurriculumLink_Line" & i).Range.Text = rst![Tbl_All_Attachments_Curriculum].[Attachment_C].[FileName]
            rst.MoveNext
        Next I

    Any suggestions? I only need the filename and not the file itself to be inserted into the Word document.

    Thanks

    Friday, August 25, 2017 5:21 AM
  • Hi all,

    I have found the solution:

    If I use .Item("CurriculumLink_Line" & i).Range.Text = rst.Fields("Attachment_C.FileName"), The filename is inserted into the Word document.

    Thanks for your assistance.

    Regards

    Deon

    • Proposed as answer by Chenchen LiModerator Friday, August 25, 2017 7:38 AM
    • Marked as answer by Deon SA Friday, August 25, 2017 7:46 AM
    Friday, August 25, 2017 6:39 AM
  • Hello Deon,

    Glad that you have resolved the issue and I suggest you mark it as answer to close this thread.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 25, 2017 7:39 AM
    Moderator