Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
      rs.MoveNext
    Wend


End Sub
ASKER CERTIFIED SOLUTION
Avatar of answer_dude
answer_dude
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

thanks very much