我有一个在 Windows 7 上运行的 MS Access 2007 VBA 应用程序。一个关键功能是将文件上传到 WebDAV 服务器。下面的代码在一台 PC 上完美运行,但在其他 PC 上失败(是的,每台 PC 的配置方式相同)。
这是在其他 PC 上失败时弹出的挪威错误消息的 translate.google.com 翻译:
Run-time error '-2147217895 (80040e19)': can not find any objects or data in accordance with the name, range or selection criteria within the scope of this operation
它在这行代码上失败:
objRecord.Open fil, "URL=" & URL, adModeReadWrite, adCreateOverwrite, adDelayFetchStream, sUsername, sPwd
完整的功能代码如下。它实际上只是重用http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/26b8e905-33d0-438b-98a7-bb69053b931e/上的代码。任何提示将不胜感激!
Function DAVPUT(ByVal URL As String, ByVal fil As String) As Boolean '
Dim sUsername As String
Dim sPwd As String
sUsername = "k@dummy.com"
sPwd = "dummy"
Dim objRecord As New ADODB.Record
Dim objStream As New ADODB.Stream
objRecord.Open fil, "URL=" & URL, adModeReadWrite, adCreateOverwrite, adDelayFetchStream, sUsername, sPwd
objStream.Type = adTypeBinary
objStream.Open objRecord, adModeWrite, adOpenStreamFromRecord
objStream.LoadFromFile fil
objStream.Flush
DoEvents
objStream.close
objRecord.close
DAVPUT = True
End Function