Access中出现运行时错误3011 [英] Runtime Error 3011 in Access
问题描述
我只是尝试使用vba导入.csv文件. 我将DoCmd.TransferText方法与自定义规范一起使用.我尝试使用相同规格的向导导入文件,并且效果很好.
I just try to import a .csv file with vba. I use the DoCmd.TransferText method with custom specs. I tried to import the file with the wizard, with the same specs and it works perfectly fine.
但是当我启动vba时,出现此错误消息:
But when I start the vba I get this error Message:
这是我的代码的一部分,我在其中调用方法:
Here is the part of my code, where I call up the method:
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
我的数据库位于网络驱动器上,但是我尝试将其复制到本地驱动器上,并且具有相同的otcome.我还尝试了文件位置".
My Database is on a Network-Drive, but I tried to copy it on my local drive and it had the same otcome. I also experimented with the File Location.
我正在使用的软件是: -Microsoft Access 2013
The Software I am using is: -Microsoft Access 2013
谢谢大家:)
推荐答案
更完整的答案:
文件名包含非ASCII字符.多重访问功能无法正确处理此问题.解决方案是将任何具有非ASCII字符的文件重命名为不包含这些字符的文件.
The filename contained non-ASCII characters. Multiple Access functions can't handle this properly. The solution is to rename any file with non-ASCII characters to something that doesn't include these characters.
一些有用的帮助器功能:
Some useful helper functions:
测试字符串是否包含非ASCII字符,如果包含则返回true,否则返回false(在这种情况下可用于引发描述性错误).
Test if a string contains non-ASCII characters and return true if it does, false if it doesn't (can be used to throw descriptive errors in this case).
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字符
Strip non-ASCII characters from a string
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
这篇关于Access中出现运行时错误3011的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!