0

I need to export a picture from an Access database, but it gives me an error. I've already tried a lot of things but nothing works.

import win32com.client
daoEngine = win32com.client.Dispatch('DAO.DBEngine.120')
db = r"D:\Shared_Folders\Projects_for_programming\Python\ZekBase\db.accdb"
daoDB = daoEngine.OpenDatabase(db)
query = "SELECT picture FROM picture WHERE check IN ('00036')"
daoRS = daoDB.OpenRecordset(query, 2)
daoAttachmentRS = daoRS.Fields["picture"].Value
daoAttachmentRS.Fields["picture"].SaveToFile("D:\Shared_Folders\Projects_for_programming\Python\ZekBase")
daoDB.Close()

the error

Traceback (most recent call last): File "D:\Shared_Folders\Projects_for_programming\Python\ZekBase\rrr.py", line 8, in daoAttachmentRS.Fields["picture"].SaveToFile("D:\Shared_Folders\Projects_for_programming\Python\ZekBase") ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'memoryview' object has no attribute 'Fields'

enter image description here

I think I need to somehow work with ole object...

6
  • Does this answer your question? Save MS ACCESS attachments with python Commented Nov 22, 2023 at 19:48
  • daoAttachmentRS.Fields["picture"].SaveToFile - "picture" should be "FileData". Commented Nov 22, 2023 at 19:50
  • Is picture an Attachment data type field? Commented Nov 22, 2023 at 20:22
  • 1
    @June7 re: "Is picture an Attachment data type field?" - Doesn't look like it. IIRC, Attachment fields in DataSheet view look like a paperclip: 📎 "Bitmap Image" probably means that it is an OLE embedded object (.bmp file wrapped with an OLE header). Commented Nov 23, 2023 at 0:47
  • 1
    @June7 - There's also this thing I wrote 10 years ago. It's C#, but the same thing could likely be done in Python. Commented Nov 23, 2023 at 1:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.