2013-07-30 46 views
0

我試圖導出一些通過VBA代碼訪問時作爲附件嵌入的圖片。出於某種原因,我不斷收到編譯錯誤:方法或數據成員沒有在.SaveToFile部分找到。訪問VBA - 未找到方法或數據成員

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 
+0

確保在'.SaveToFile'之後,如果您要使用代碼換行,則需要放置'&_',而不僅僅是下劃線。 – Grant

回答

0

該附件是在Recordset2對象(和Field2):

Set rsPicture = New ADODB.Recordset2 

作爲錯誤消息指出,實際上,一個Field對象不具有SaveToFile法,Field2對象確實。

有一個比幫助系統here中找到的更完整的例子。

相關問題