ACC: Cannot Trap Import Errors in Visual Basic for ApplicationsID: Q169956
|
Moderate: Requires basic macro, coding, and interoperability skills.
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.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
The same rules that apply to manual data entry also apply to methods for
importing data in 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 1.x and 2.0, a violation of these rules generates a
trappable error, which makes it possible for developers to determine if the
import completed successfully. In Microsoft Access 7.0 and 97, this
behavior has changed so that no trappable error is generated. Furthermore,
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
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.
Keywords : kbinterop kbprg IsmTxtd IsmTxtfx IsmExl4 IsmExl5 PgmErr
Version : 7.00 97
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 22, 1999