I have a form with one button the code for that button is
This is a text box that contains the location of the file being imported
I am aware that "On Error Resume Next" is the improper way to deal with error handling but I haven't been able to find a solution to fix the problem I have
The Problem is that, in case that a spread sheet doesn't match any of the 4 or doesn't meet the format then show a error message that states "Import file is not in the correct format." but I don't want to show a error message for any of the DoCmd.TransferS preadsheet and no matter what there will be an error message for them because I can only import one spreadsheet at a time and they are located on 3 seperate spreadsheets/workbooks.
The code that i've attempted to fix the problem is this
Using this code no matter what, I get an error for atleast one of the transferspreads heets. It would pass one then import then error or not import any data and just error.
Please help!
Thanks.
Code:
On Error Resume Next DoCmd.TransferSpreadsheet acImport, 8, "FuelConsumption NewData", Me.tb_FileName, 1, "sheet2$" On Error Resume Next DoCmd.TransferSpreadsheet acImport, 8, "Inbound NewData", Me.tb_FileName, 1, "Inbound Trains$" DoCmd.TransferSpreadsheet acImport, 8, "Outbound NewData", Me.tb_FileName, 1, "Outbound Trains$" On Error Resume Next DoCmd.TransferSpreadsheet acImport, 8, "LPMH NEWDATA", Me.tb_FileName, 1 ', "March 09$" MsgBox "Import Complete"
Code:
Me.tb_FileName
I am aware that "On Error Resume Next" is the improper way to deal with error handling but I haven't been able to find a solution to fix the problem I have
The Problem is that, in case that a spread sheet doesn't match any of the 4 or doesn't meet the format then show a error message that states "Import file is not in the correct format." but I don't want to show a error message for any of the DoCmd.TransferS preadsheet and no matter what there will be an error message for them because I can only import one spreadsheet at a time and they are located on 3 seperate spreadsheets/workbooks.
The code that i've attempted to fix the problem is this
Code:
'On Error GoTo Err1 ' DoCmd.TransferSpreadsheet acImport, 8, "FuelConsumption NewData", Me.tb_FileName, 1, "sheet2$" ' MsgBox "FuelConsumption Import Complete" 'On Error Resume Next 'Err1: 'On Error GoTo Err2: 'DoCmd.TransferSpreadsheet acImport, 8, "Inbound NewData", Me.tb_FileName, 1, "Inbound Trains$" 'DoCmd.TransferSpreadsheet acImport, 8, "Outbound NewData", Me.tb_FileName, 1, "Outbound Trains$" 'MsgBox "Inbound/Outbound Import Complete" 'On Error Resume Next 'Err2: 'On Error GoTo Err3: 'DoCmd.TransferSpreadsheet acImport, 8, "LPMH NEWDATA", Me.tb_FileName, 1 ', "March 09$" 'MsgBox "LPMH Import Complete" 'On Error Resume Next 'Err3: 'MsgBox "The Import data selected is not in the correct format" 'Exit Sub
Run-Time Error '3125'
Thanks.
Comment