How to auto attach images in Access 2010 using vba/macros?

前端 未结 3 978
青春惊慌失措
青春惊慌失措 2021-01-16 04:13

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 databa

3条回答
  •  轮回少年
    2021-01-16 04:49

    On Error GoTo Err_AddImage Dim db As DAO.Database Dim rsParent As DAO.Recordset2 Dim rsChild As DAO.Recordset2 Set db = CurrentDb Set rsParent = Me.Recordset rsParent.Edit Set rsChild = rsParent.Fields("AttachmentTest").Value rsChild.AddNew rsChild.Fields("FileData").LoadFromFile ("c:\Sunset.jpg") rsChild.Update rsParent.Update Exit_AddImage: Set rsChild = Nothing Set rsParent = Nothing Exit Sub Err_AddImage: If Err = 3820 Then MsgBox ("File already part of the multi-valued field!") Resume Next Else MsgBox "Some Other Error occured!", Err.Number, Err.Description Resume Exit_AddImage End If

提交回复
热议问题