Results 1 to 2 of 2
  1. #1
    dwoldike is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2016
    Posts
    1

    MS Access Save Ole Objects to folder

    I have anaccess database with a table that has an OLE object field, where there isvarious type of files attached, but only one file per record.

    I am trying tosave these files to different folders, but do not know how to create a VBA code,that can go through each record an save the embedded file to a folder that I define.

    I´ve found somecode, but get an error in line “Set rsA = fld.Value” that it is missing anobject…

    FunctionSaveAttachments()

    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset2
    Dim rsA As DAO.Recordset2
    Dim fld As DAO.Field2
    Dim strFullPath As String

    'Get the database, recordset, andattachment field
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("TEMP_IC_DOCUMENTS")
    Set fld = rst("DOC_Attachment")

    'Navigate through the table
    Do While Not rst.EOF

    'Get the recordset for the Attachmentsfield
    Set rsA = fld.Value

    'Save all attachments in the field
    Do While Not rsA.EOF
    MsgBox rsA("FileName")
    If rsA("FileName") LikestrPattern Then
    strFullPath ="e:\temp\test" & rsA("FileName")

    'Make sure the file does notexist and save
    If Dir(strFullPath) ="" Then
    rsA("FileData").SaveToFile strFullPath
    End If

    'Increment the number of filessaved
    SaveAttachments =SaveAttachments + 1
    End If

    'Next attachment
    rsA.MoveNext
    Loop
    rsA.Close

    'Next record
    rst.MoveNext
    Loop

    rst.Close
    dbs.Close

    Set fld = Nothing
    Set rsA = Nothing
    Set rst = Nothing
    Set dbs = Nothing
    End Function

    Anyone whoknows how to do this ?


  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    I don't see how that code would even compile. Instead of rsA("FileName") the syntax should be rsA!FileName. I don't have a database with an OLE Object field in a table so cannot test. A proven solution can be obtained from Leban's website at http://www.lebans.com/oletodisk.htm

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Can't save database objects when changes made
    By stanley721 in forum Access
    Replies: 8
    Last Post: 10-12-2015, 08:51 PM
  2. How to save report as PDF in certain folder
    By kassem in forum Programming
    Replies: 4
    Last Post: 06-04-2014, 07:42 AM
  3. Replies: 43
    Last Post: 03-27-2014, 01:51 AM
  4. Save report to a folder
    By Gilgamesh in forum Programming
    Replies: 2
    Last Post: 12-23-2012, 07:25 PM
  5. save folder to another directory
    By focosi in forum Programming
    Replies: 7
    Last Post: 08-30-2011, 07:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums