在Access中将图像另存为OLE对象 [英] Saving Image as OLE Object, in Access
问题描述
我有一个表,其中的字段是OLE对象类型的.然后,我有了一个包含许多字段的表单.有些只是文本字段.但是,我在窗体上也有一个Image对象.用户单击按钮时,将打开一个对话框,他们可以为照片拍照.一旦他们选择了照片,Image对象就会显示该照片.我想将该图像保存到数据库.我似乎只是在计算机上保存了文件所在位置的引用.因此,如果数据库被移动,这将不起作用.这是我的代码:
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
如何将图像文件保存到OLE字段,以便以后可以将其重新加载到窗体上的Image对象?
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?
谢谢
答案:
因此,我最终要做的是遵循此 https://support.microsoft. com/en-us/kb/210486
So, what I ended up doing was following this https://support.microsoft.com/en-us/kb/210486
我使用readBLOB函数读取文件并将其保存到数据库中.然后,当我运行报表或打开包含图片的窗体时,在加载时,我使用WriteBlob函数将文件写入临时文件夹,然后使用该路径填充Image对象.
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.
推荐答案
当您开始嵌入图像时,数据库可能会增长到巨大的规模,从而导致查询速度变慢,崩溃,超时和用户不满意.将图像添加到数据库时,请谨慎使用OLE
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
简单的Google搜索具有如何将文件夹中的ole对象加载到表中
Simple Google search has how to load ole object from folder into table
此站点上的搜索出现 查看全文