I am using following routine to lift data from Excel files into Access tables. Whole thing works, well, most of the time. The only issue I have is the spreadsheets are received from warehouses and even though they have been given strict instruction to stick to the template, I have had to adjust the spreadsheets. Amongst errors I get are:
Field 'F16' does not exist in table 'SA1'. (In this case I simply delete the last most empty column to fix this).
Or there are column name spellings and in such cases, I get no error and the simply code hangs.
Is there any routine that I could incorporate in the code that clearly states what issues are being experienced. This way I can pass the db to the user to run it themselves.
'Dim dbs As Database, tdf As TableDef
Set dbs = CurrentDb
On Error GoTo Macro1_Err
DoCmd.SetWarnings False
' RunSQL executes a SQL string
DoCmd.RunSQL "DELETE FROM NSW1;"
DoCmd.RunSQL "DELETE FROM [QLD1];"
DoCmd.RunSQL "DELETE FROM [SA1];"
DoCmd.RunSQL "DELETE FROM [VIC1];"
DoCmd.RunSQL "DELETE FROM [WA1];"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "NSW1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\NSW SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "QLD1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\QLD SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "SA1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\SA SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "VIC1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\vic SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "WA1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\WA SOH.xls", True
DoCmd.SetWarnings True
Set dbs = Nothing
MsgBox ("All Data updated")
Call DeleteImportErrorTables
Macro1_Exit:
Exit Sub
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Sub
Field 'F16' does not exist in table 'SA1'. (In this case I simply delete the last most empty column to fix this).
Or there are column name spellings and in such cases, I get no error and the simply code hangs.
Is there any routine that I could incorporate in the code that clearly states what issues are being experienced. This way I can pass the db to the user to run it themselves.
'Dim dbs As Database, tdf As TableDef
Set dbs = CurrentDb
On Error GoTo Macro1_Err
DoCmd.SetWarnings False
' RunSQL executes a SQL string
DoCmd.RunSQL "DELETE FROM NSW1;"
DoCmd.RunSQL "DELETE FROM [QLD1];"
DoCmd.RunSQL "DELETE FROM [SA1];"
DoCmd.RunSQL "DELETE FROM [VIC1];"
DoCmd.RunSQL "DELETE FROM [WA1];"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "NSW1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\NSW SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "QLD1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\QLD SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "SA1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\SA SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "VIC1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\vic SOH.xls", True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "WA1", "\\Nnorsogfas031\NSP\SOH\SOH Reports\WA SOH.xls", True
DoCmd.SetWarnings True
Set dbs = Nothing
MsgBox ("All Data updated")
Call DeleteImportErrorTables
Macro1_Exit:
Exit Sub
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Sub