访问VBA - 找不到方法或数据成员

时间:2013-07-30 14:23:49

标签: ms-access access-vba

我正在尝试通过VBA代码导出一些作为附件嵌入的图片。出于某种原因,我不断收到编译错误:.SaveToFile部分找不到方法或数据成员。

   Private Sub btnExport_Click()
'  Instantiate the parent recordset.

Dim rsPicture As ADODB.Recordset
Set rsPicture = New ADODB.Recordset

rsPicture.ActiveConnection = CurrentProject.Connection

rsPicture.Open "Select * from Pictures"

rsPicture.MoveFirst

 '  Set rsPicture = db.OpenRecordset("Pictures")


   ' Instantiate the child recordset.
   Set rsPicture = rsPictureTable.Fields("Picture").Value

   '  Loop through the attachments.
   While Not rsPicture.EOF

      '  Save current attachment
      rsPicture.Fields("FileData").SaveToFile _
                  "C:\Pics"
      rsPicture.MoveNext
   Wend

End Sub

1 个答案:

答案 0 :(得分:0)

附件位于Recordset2对象(和Field2)中:

Set rsPicture = New ADODB.Recordset2

正如错误消息所说,Field对象实际上没有SaveToFile方法,Field2对象可以。

有一个比帮助系统here中找到的更完整的例子。