Saving Image as OLE Object, in Access

天大地大妈咪最大 提交于 2019-12-13 07:21:23

问题


I have a table with a field that is of type OLE Object. I then have a form with a number of fields. Some are just text fields. But, I also have an Image object on the form. When a user clicks a button, a dialog opens and they can pic a photo. Once they select the photo, the Image object displays that picture. I want to save that image to database. What I have only seems to save a reference to where the file is located, on the computer. So, this would not work if the db is moved. Here is the code I have:

Dim wrkCurrent As DAO.Workspace
Dim dbs As DAO.Database
Dim rstPerson As DAO.Recordset

Set wrkCurrent = DBEngine.Workspaces(0)
Set dbs = CurrentDb
Set rstPerson = dbs.OpenRecordset("SELECT * FROM tbl_person WHERE id =" & ID)

With rstPerson
 .Edit
      !bio_photo = Me.Image37.picture
 .Update
End With

How would I save the image file to the OLE Field, so that I could load it back to the Image object, on the form, at a later time?

Thanks

Answer:

So, what I ended up doing was following this https://support.microsoft.com/en-us/kb/210486

I use the readBLOB function to read the file and save it into the database. Then, when I run a report or open a form that has the picture, onload, I use the WriteBlob function to write the file to a temp folder and then use that path to populate an Image object.


回答1:


Databases can grow to enormous sizes when you start embedding images, leading to slower queries, crashes, timeouts, and dissatisfied users. Use OLE with caution when adding images into a database

Simple Google search has how to load ole object from folder into table

And a search on this site comes up with auto attach images using vba



来源:https://stackoverflow.com/questions/37753820/saving-image-as-ole-object-in-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!