Public Function VerifyImportErrorTables()
On Error GoTo Err_VerifyImportErrorTables
Dim tblDef As TableDef
For Each tblDef In CurrentDb.TableDefs
If InStr(1, tblDef.Name, "ImportError") > 0 Then
Beep
MsgBox "There was an error importing all of your records." & vbCrLf & vbLf & "An error report will be sent to your default printer. Only the first ten pages of the report will be printed." & vbCrLf & vbLf & "The error report will detail the error reason for each field and row number for each record [up to the first ten pages] that was not successfully imported from your file." & vbCrLf & vbLf & "Please correct all errors and import your data again." & vbCrLf & vbLf & "Do not cancel the print job or else the error table will not be deleted.", vbInformation, "Import Errors"
DoCmd.SelectObject acTable, tblDef.Name, True
DoCmd.PrintOut acPages, 1, 2 'only print the first two pages
DoCmd.DeleteObject acTable, tblDef.Name
End If
Next tblDef
Exit_VerifyImportErrorTables:
Exit Function
Err_VerifyImportErrorTables:
If Err = 2501 Then 'The PrintOut action was canceled. You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box.
Beep
MsgBox "You cancelled printing the error table report." & vbCrLf & vbLf & "The program was not allowed to delete the error table and will be printed the next time you import a data file.", vbCritical, "Print Error Table Aborted"
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_VerifyImportErrorTables
End If
End Function