Access 中的运行时错误 3011

Runtime Error 3011 in Access

我只是尝试使用 vba 导入 .csv 文件。 我使用自定义规格的 DoCmd.TransferText 方法。我尝试使用向导导入文件,具有相同的规格,并且效果非常好。

但是当我启动 vba 时,我收到此错误消息:

Sorry, it is in german, but I think one can read the essentials

这是我的代码部分,我在其中调用方法:

Public Function ImportFileToTable(params As ImportFileToTableParams) As ImportFileToTableResult
    'TODO: Import a CSV File into the selected table
    Dim result As New ImportFileToTableResult

    On Error GoTo ImportFail
    DoCmd.TransferText acImportDelim, params.SpecificationName, params.TableName, params.FileName, params.HasFieldNames

    result.Success = True
    Set ImportFileToTable = result
    Exit Function

ImportFail:
    result.Success = False
    result.ErrorMessage = "There was an error importing the File"
    Set ImportFileToTable = result
End Function

我的数据库在网络驱动器上,但我试图将它复制到我的本地驱动器上,但它有同样的结果。我还尝试了文件位置。

我使用的软件是: -Microsoft Access 2013

提前谢谢大家:)

更完整的答案:

文件名包含非 ASCII 字符。多路访问功能无法正确处理此问题。解决方案是将任何包含非 ASCII 字符的文件重命名为不包含这些字符的名称。

一些有用的辅助函数:

测试字符串是否包含非 ASCII 字符,return如果包含则为真,否则为假(在这种情况下可用于抛出描述性错误)。

Public Function StringContainsNonASCII(str As String) As Boolean
    Dim i As Integer
    'Default is false
    StringContainsNonASCII = False
    'Remove question marks
    str = Replace(str, "?", "")
    For i = 1 To Len(str)
        'Search for question marks
        If Asc(Mid(str, i, 1)) = 63 Then
            StringContainsNonASCII = True
            Exit Function
        End If
    Next i
End Function

从字符串中去除非 ASCII 字符

Public Function RemoveNonASCII(str As String) As String
    Dim i As Integer
    For i = 1 To Len(str)
        'Append the question marks
        If Mid(str, i, 1) = "?" Then
            RemoveNonASCII = RemoveNonASCII & "?"
        End If
        'Append anything that isn't a questionmark
        If Asc(Mid(str, i, 1)) <> 63 Then
            RemoveNonASCII = RemoveNonASCII & Chr(Asc(Mid(str, i, 1)))
        End If
    Next i
End Function