如何使用vba/macros在Access 2010中自动附加图像? [英] How to auto attach images in Access 2010 using vba/macros?

查看:105
本文介绍了如何使用vba/macros在Access 2010中自动附加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中有一个带有文件名称的照片"文本字段.我还将实际文件放在单独的文件夹中.我想将这些文件附加到数据库,而不是将它们保存在单独的文件夹中.因此,我创建了一个单独的图片"附件字段.但是我不知道如何将这些文件自动附加到此字段.你能给我一些指示吗?

I have a table where there is a "Photo" text field with the name of the file. I also have the actual files in a separate folder. I want to attach those files to the database, and not keep them in a separate folder. So I've created a separate "Picture" attachment field. But I don't know how I can attach those files to this field automatically. Can you give me some directions?

推荐答案

附件与OLE对象完全不同.应该压缩第一个文件,并在没有在计算机上安装OLE服务器的情况下进行管理.例如,当您将OLE对象添加到MS-Access字段时,该对象将以一种位图的形式进行转换,该位图应该非常大.在附件字段中,几种文件格式会自动在数据库上压缩.另外,您不仅可以导入一个文件,还可以导入多个文件.在这种情况下,Access会在后台使用关系数据库模型来提高效率.

Attachments are quite different from OLE objects. The first should be compacted and are managed without OLE servers installed on machine. For example, when you add a OLE object to a MS-Access field, this object is transformed in a kind of bitmap, which ought to be very large. In attachment fields, several file formats are automatically compacted on database. Also, you are able to import more than just only one file. In this case, Access does, behind the scenes, relational database model for improving efficiency.

您应按如下所示在附件字段中加载和保存文件格式:

You should load and save file formats in attachment fields as follows:

'  Instantiate the parent recordset. 
   Set rsEmployees = db.OpenRecordset("Employees")

   '… Code to move to desired employee

   ' Activate edit mode.
   rsEmployees.Edit

   ' Instantiate the child recordset.
   Set rsPictures = rsEmployees.Fields("Pictures").Value 

   ' Add a new attachment.
   rsPictures.AddNew
   rsPictures.Fields("FileData").LoadFromFile "EmpPhoto39392.jpg"
   rsPictures.Update

   ' Update the parent record
   rsEmployees.Update

'  Instantiate the parent recordset. 
   Set rsEmployees = db.OpenRecordset("Employees")

   '… Code to move to desired employee

   ' Instantiate the child recordset.
   Set rsPictures = rsEmployees.Fields("Pictures").Value 

   '  Loop through the attachments.
   While Not rsPictures.EOF

      '  Save current attachment to disk in the "My Documents" folder.
      rsPictures.Fields("FileData").SaveToFile _
                  "C:\Documents and Settings\Username\My Documents"
      rsPictures.MoveNext
   Wend

有关更多信息,请访问 http: //msdn.microsoft.com/pt-br/library/bb258184%28v=office.12%29.aspx

for more information, visit http://msdn.microsoft.com/pt-br/library/bb258184%28v=office.12%29.aspx

这篇关于如何使用vba/macros在Access 2010中自动附加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆