Murray Brown
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("Attachme nts")
' … 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").SaveTo File MYDOC_DIR 'ERROR HERE
rs.MoveNext
Wend
End Sub
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("Attachme
' … 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").SaveTo
rs.MoveNext
Wend
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER