|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
如题:找网上的代码写的如下代码,只能给第一个记录添加图片附件,请教如何实现任意指定的ID添加,谢谢!
Sub 修改()
Dim attachmentPath As String
Dim conn As Object
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\质量风险档案V1.accdb;"
Dim rs As Object
Set rs = CreateObject("ADODB.Recordset")
rs.Open "问题", conn, 2, 2
attachmentPath = "d:\问题.jpg" ' 附件文件的路径
Dim attachmentData() As Byte
Open attachmentPath For Binary Access Read As #1
ReDim attachmentData(LOF(1) - 1)
Get #1, , attachmentData
Close #1
Dim attachmentField As Object
Set attachmentField = rs.Fields("图片")
attachmentField.AppendChunk attachmentData
rs.Update
rs.Close
conn.Close
Set conn = Nothing
End Sub
|
|