ACC2000: Cannot Trap Import Errors in Visual Basic for ApplicationsID: Q197596
|
In Visual Basic for Applications, you cannot trap for import errors generated when you use the TransferText or the TransferSpreadsheet method to import or append data to a Microsoft Access table.
The same rules that apply to manual data entry also apply to methods for
importing data when using Visual Basic for Applications. Therefore, any
violations of rules, such as referential integrity, validation rules, or
the Required property, will result in an incomplete import.
In Microsoft Access 2000, no trappable error is generated and if the
procedure disables system messages by using the SetWarnings statement, there is no indication that any problem occurred.
OrderID,ProductID,UnitPrice,Quantity,Discount
99999,54,7.45,20,0.000
Option Explicit
Sub ImportOrderDetails()
On Error GoTo ImportOrderDetails_Error
DoCmd.TransferText acImportDelim, _
"Order Details Specification", _
"Order Details", "C:\My Documents\OrdDetails.txt"
Exit_ImportOrderDetails:
Exit Sub
ImportOrderDetails_Error:
MsgBox "Error Handler was invoked."
MsgBox CStr(Err) & " " & Err.Description
Resume Exit_ImportOrderDetails
End Sub
ImportOrderDetails
Click Yes. Note that the error handler is never executed. This indicates that the procedure did not encounter a trappable error.Microsoft Access was unable to append all the data to the table.
The contents of fields in 0 records(s) were deleted, and 1 record(s) were lost due to key violations.... Do You want to proceed anyway?
Additional query words: visual basic for applications
Keywords : kbdta IsmTxtd IsmTxtfx IsmExl4 IsmExl5 PgmErr
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 15, 1999