如果消息 "Microsoft Access was unable to append all data....",如何让 Access 2010 创建错误 Table
How to I get Access 2010 to creating an Error Table if message "Microsoft Access was unable to append all data...."
我有一个 vba 可以将数据从 excel 导入到 Access 2010 table。问题是 Access table 有一些字段验证,这是错误消息的原因。我对错误没有意见,但我希望将有错误的行粘贴到错误 table 中。此外,excel 数据不是我提供的,因此我无法在导入前验证数据。我想将 "error table" 发送给发送给我的人以更正数据。这是我发现并有效的导入 vba。
Public Function GetMyFile() As Boolean
On Error Resume Next
Dim fdFilePick As FileDialog
Dim varSelectedFile As Variant
Dim strInFile As String
Dim strImport70 As String
Set fdFilePick = Application.FileDialog(msoFileDialogFilePicker)
DoCmd.Hourglass True
With fdFilePick
.AllowMultiSelect = False
.ButtonName = "&Import"
.InitialFileName = Application.CurrentProject.Path
.Filters.Add "Excel", "*.xlsx"
If .Show Then
For Each varSelectedFile In .SelectedItems
strInFile = CStr(varSelectedFile)
DoCmd.DeleteObject acTable, strImport70
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Import70", strInFile, True
Next
Else
MsgBox "Import Process Canceled", vbCritical, "Import Canceled"
GetMyFile = False
Exit Function
End If
End With
End Function
如果 none 有道理,请提问。我只是觉得必须有一种方法来捕获有错误的行。
谢谢大家!
当使用 VBA 导入数据时,Access 不会像您 copy/paste数据放入 table.
您可以做的是创建一个 table 的副本作为 TempImport table 并删除所有会阻止行被导入的约束(验证)。然后将 Excel 数据导入此 TempImport table。现在使用代码 and/or 查询来验证 TempImport 中的数据。如果所有行都很好,请将它们从您的 TempImport table 附加到您的最终 table。如果有任何行是错误的,请将它们导出为您想要的格式以发回,然后丢弃 TempImport 中的所有内容。
我有一个 vba 可以将数据从 excel 导入到 Access 2010 table。问题是 Access table 有一些字段验证,这是错误消息的原因。我对错误没有意见,但我希望将有错误的行粘贴到错误 table 中。此外,excel 数据不是我提供的,因此我无法在导入前验证数据。我想将 "error table" 发送给发送给我的人以更正数据。这是我发现并有效的导入 vba。
Public Function GetMyFile() As Boolean
On Error Resume Next
Dim fdFilePick As FileDialog
Dim varSelectedFile As Variant
Dim strInFile As String
Dim strImport70 As String
Set fdFilePick = Application.FileDialog(msoFileDialogFilePicker)
DoCmd.Hourglass True
With fdFilePick
.AllowMultiSelect = False
.ButtonName = "&Import"
.InitialFileName = Application.CurrentProject.Path
.Filters.Add "Excel", "*.xlsx"
If .Show Then
For Each varSelectedFile In .SelectedItems
strInFile = CStr(varSelectedFile)
DoCmd.DeleteObject acTable, strImport70
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Import70", strInFile, True
Next
Else
MsgBox "Import Process Canceled", vbCritical, "Import Canceled"
GetMyFile = False
Exit Function
End If
End With
End Function
如果 none 有道理,请提问。我只是觉得必须有一种方法来捕获有错误的行。
谢谢大家!
当使用 VBA 导入数据时,Access 不会像您 copy/paste数据放入 table.
您可以做的是创建一个 table 的副本作为 TempImport table 并删除所有会阻止行被导入的约束(验证)。然后将 Excel 数据导入此 TempImport table。现在使用代码 and/or 查询来验证 TempImport 中的数据。如果所有行都很好,请将它们从您的 TempImport table 附加到您的最终 table。如果有任何行是错误的,请将它们导出为您想要的格式以发回,然后丢弃 TempImport 中的所有内容。