我正嘗試在Access中的一個窗體上創建一個按鈕,將文件從一個文件夾移動到另一個文件夾。該項目的文件路徑存儲在數據庫中。我目前的做法是使用VB並顯示在這裏。在MSOffice Access 2010中移動文件
Private Sub Command21_Click()
Dim d As Database
Dim r As Recordset
Dim path As Field
Dim fromPath As String
Dim toPath As String
Set d = CurrentDb()
Set r = d.OpenRecordset("Documents")
Set path = r.Fields("Action Items Location")
While Not r.EOF
fromPath = path
Set toPath = My.Computer.FileSystem.GetParentPath(fromPath) 'Error line
toPath = toPath & "\to folder"
My.Computer.FileSystem.MoveFile fromPath, toPath
Wend
End Sub
我不斷收到一個錯誤,指出在標記爲錯誤行的行上需要的對象。我該如何解決這個錯誤,或者我甚至以正確的方式去解決這個問題?
嘗試沒有「設置」或看看可能的錯誤異常這裏http://msdn.microsoft.com/en-us/library/b573ycc1(v=vs.90).aspx –
原本沒有「設置」,它仍然有相同的錯誤。實際上,我在審查後添加了這個設置:http://msdn.microsoft.com/en-us/library/office/gg251554.aspx – madattarp
您使用的是VBA還是VB?從這個鏈接看來,'My.Computer.FileSystem.GetParentPath()'是一個VB函數,可能在VBA中找不到。 – Zaider