如何解决目标表中不存在该字段
我有一个备份系统,出于各种原因,该系统会将表中的数据导出到.txt文件。我使用文本流对象,因为我在使用通常的导出方法截断小数位数时遇到了问题(这是一个众所周知的问题):
Sub ExportTables(fso As Object,exportPath As String,arr() As String)
Dim x As Integer
Dim recSet As Recordset
Dim fieldString As String
Dim fld As Variant
Dim txtStream As Object
For x = 0 To UBound(arr)
fso.CreateTextFile exportPath & "\" & arr(x) & ".txt"
Set txtStream = fso.OpenTextFile(exportPath & "\" & arr(x) & ".txt",8,Format:=TristateTrue)
Set recSet = CurrentDb.OpenRecordset(arr(x))
With recSet
fieldString = ""
For Each fld In .fields
fieldString = fieldString & "," & Chr(34) & fld.Name & Chr(34)
Next fld
fieldString = Right(fieldString,Len(fieldString) - 1)
txtStream.WriteLine fieldString
While Not .EOF
fieldString = ""
For Each fld In .fields
If fld.Type = dbText Or fld.Type = dbMemo Then
fieldString = fieldString & "," & Chr(34) & fld.value & Chr(34)
Else
fieldString = fieldString & "," & fld.value
End If
Next fld
fieldString = Right(fieldString,Len(fieldString) - 1)
txtStream.WriteLine fieldString
.movenext
Wend
End With
txtStream.Close
Next x
End Sub
这可以很好地创建文件。但是,当我尝试导入这些文件时,出现错误:
目标表'The_Table_In_Question'中不存在字段'ÿþ'。
使用代码:
DoCmd.TransferText acImportDelim,TableName:=arr(x),Filename:=fp & arr(x) & ".txt",HasFieldNames:=True
无论使用哪个表,都会发生相同的错误,包括相同的奇怪字段名称“ name”。
我已经通过外部数据对话框将一些备份文件上传到新表中,每次导入都没有问题,并且没有意外字段。
我将这些备份文件中的粘贴数据复制到新的文本文件中(从字面上全选,复制,粘贴),并使用上面的代码很好地上传了这些文件,因此我认为这会导致某种不可打印的字符异常文字流。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。