Hi,
I am trying to import some Tables from Text files. After the Import is done I want a function to capture all the "Import Error Tables" and send a email with attachment(of the error Tables) and delete the error Tables from the data base. I have tried the below function. The delete works but email doesnot work. Can someone please help.
Public Function VerifyImportErrorTables()
On Error GoTo Err_VerifyImportErrorTables
Dim tblDef As TableDef
Dim strEmailTo As String, strCopyTo As String, strSubject As String
strEmailTo = "ravikode1@yahoo.com"
strCopyTo = "ravikode1@yahoo.com"
strSubject = "Import Error Tables on "
For Each tblDef In CurrentDb.TableDefs
If InStr(1, tblDef.Name, "ImportError") > 0 Then
DoCmd.SelectObject acTable, tblDef.Name, True
'DoCmd.SendObject acSendReport, strTable, acFormatRTF, to:=strEmailTo, cc:=strCopyTo, _
subject:=strSubject, editmessage:=False
'DoCmd.OutputTo acOutputTable, strTable, acFormatRTF, "C:\Temp\ErrorTable.RFT"
DoCmd.DeleteObject acTable, tblDef.Name
MsgBox "There was an error importing all of your records." & vbCrLf & vbLf & "An error report was sent to your default printer." & vbCrLf & vbLf & "The error report will detail the error reason for each field and row number for each record that was not successfully imported from your file." & vbCrLf & vbLf & "Please correct all errors and import your data again.", vbInformation, "Import Errors"
End If
Next tblDef
Exit_VerifyImportErrorTables:
Exit Function
Err_VerifyImportErrorTables:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_VerifyImportErrorTables
End Function
I am trying to import some Tables from Text files. After the Import is done I want a function to capture all the "Import Error Tables" and send a email with attachment(of the error Tables) and delete the error Tables from the data base. I have tried the below function. The delete works but email doesnot work. Can someone please help.
Public Function VerifyImportErrorTables()
On Error GoTo Err_VerifyImportErrorTables
Dim tblDef As TableDef
Dim strEmailTo As String, strCopyTo As String, strSubject As String
strEmailTo = "ravikode1@yahoo.com"
strCopyTo = "ravikode1@yahoo.com"
strSubject = "Import Error Tables on "
For Each tblDef In CurrentDb.TableDefs
If InStr(1, tblDef.Name, "ImportError") > 0 Then
DoCmd.SelectObject acTable, tblDef.Name, True
'DoCmd.SendObject acSendReport, strTable, acFormatRTF, to:=strEmailTo, cc:=strCopyTo, _
subject:=strSubject, editmessage:=False
'DoCmd.OutputTo acOutputTable, strTable, acFormatRTF, "C:\Temp\ErrorTable.RFT"
DoCmd.DeleteObject acTable, tblDef.Name
MsgBox "There was an error importing all of your records." & vbCrLf & vbLf & "An error report was sent to your default printer." & vbCrLf & vbLf & "The error report will detail the error reason for each field and row number for each record that was not successfully imported from your file." & vbCrLf & vbLf & "Please correct all errors and import your data again.", vbInformation, "Import Errors"
End If
Next tblDef
Exit_VerifyImportErrorTables:
Exit Function
Err_VerifyImportErrorTables:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_VerifyImportErrorTables
End Function