• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

Access VBA - Saving Word attachment error

Hi. I am using the following code to try to save a word document from the Field1 field,
which is an attachment field to "My Documents"
On the line where I have put "ERROR HERE" the code falls over saying "Invalid field data type"

Sub Save_Word_Attachment()

    Dim MYDOC_DIR As String
    MYDOC_DIR = Environ("userprofile") & "\my documents"
    Dim DB As Database
    Dim rs As DAO.Recordset
    Dim rsField1 As DAO.Recordset2
    Set DB = CurrentDb

    '  Instantiate the parent recordset.
    Set rs = DB.OpenRecordset("Attachments")
    ' … Code to move to desired employee
    ' Instantiate the child recordset.
    Set rsField1 = rs.Fields("Field1").Value  'the Field1 field holds the attachments
    '  Loop through the attachments.
    While Not rs.EOF
      '  Save current attachment to disk in the "My Documents" folder.
      rs.Fields("Field1").SaveToFile MYDOC_DIR  'ERROR HERE

End Sub
Murray Brown
Murray Brown
1 Solution
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now