Anton Hughes
Anton Hughes

Reputation: 1995

How to validate that an excel file has been imported into MS Access successfully?

Can't seem to find this answer anywhere online, so here we go.

I have a bit of code that pulls in an excel file and inputs its data into a table into a table within MS Access 2007.

How can I validate that the file has imported successfully?

For example:

If excel did import Then
MsgBox "Import successful"
Else If Excel didnt import
MsgBox "Import Not successful"

I am currently importing the excel file by using the following code:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblData", "FilePath", True, "Sheet1!"

Thanks

Upvotes: 1

Views: 2081

Answers (1)

Anton Hughes
Anton Hughes

Reputation: 1995

Finally got it after looking around!

Put this code after the 'DoCmd.TransferSpreadsheet' code.

If DBEngine.Errors.Count = 0 Then

    MsgBox "Imported data successfully!"

ElseIf DBEngine.Errors.Count > 0 Then

    MsgBox "The file did not import!"
    Exit Sub

End If

Upvotes: 5

Related Questions