I have a form with one button the code for that button is - 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"
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.TransferSpreadsheet 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 - '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
Using this code no matter what, I get an error for atleast one of the transferspreadsheets. It would pass one then import then error or not import any data and just error.
Run-Time Error '3125'
Please help!
Thanks.
5 8338 ADezii 8,834
Recognized Expert Expert
I'm a little confused as to what exactly you are asking but I think that
may help. This line effectively disables Error Handling in the Procedure in which it is invoked.
Where would i place that statement?
Hopefully this explanation will help.
I have one text box to one location of one excel spreadsheet
I have one button and that button gets the location of the file from the text box but it has to get 3 different locations in order to import all the data.
Example:
to Import file "test2.xls"
for table 2
it goes through
DoCmd.TransferSpreadsheet acImport, 8, "Table 1", Me.tb_FileName, 1, "Test1"
DoCmd.TransferSpreadsheet acImport, 8, "Table 2", Me.tb_FileName, 1, "Test2"
DoCmd.TransferSpreadsheet acImport, 8, "Table 3", Me.tb_FileName, 1, "Test3"
So in order to get to import "test2.xls" it erros at Test1 then imports through Test2 and errors at Test3.
I don't want it to error for neither of them but, I do want it to error if it erros for ALL of them (if the spreadsheet being imported doesn't meet the criteria for Test1, Test2,Test3).
ADezii 8,834
Recognized Expert Expert
This is a rather unusual request, but assuming I now understand your dilemma correctly, the following code will generate an Error Message only under the condition that ALL THREE TransferSpreadsheet() actions produce an Error. If only 1, None, or 2 fail, the Error Message will not appear. - Dim intNumOfErrors As Integer
-
On Error Resume Next
-
-
intNumOfErrors = 0 'Initialize
-
-
DoCmd.TransferSpreadsheet acImport, 8, "Table 1", Me.tb_FileName, 1, "Test1"
-
If Err.Number <> 0 Then 'Error!
-
intNumOfErrors = intNumOfErrors + 1
-
Err.Clear 'Clear the Error Object
-
End If
-
-
DoCmd.TransferSpreadsheet acImport, 8, "Table 2", Me.tb_FileName, 1, "Test2"
-
If Err.Number <> 0 Then 'Error!
-
intNumOfErrors = intNumOfErrors + 1
-
Err.Clear 'Clear the Error Object
-
End If
-
-
DoCmd.TransferSpreadsheet acImport, 8, "Table 3", Me.tb_FileName, 1, "Test3"
-
If Err.Number <> 0 Then 'Error!
-
intNumOfErrors = intNumOfErrors + 1
-
Err.Clear 'Clear the Error Object
-
End If
-
-
If intNumOfErrors = 3 Then
-
MsgBox "All 3 Imports Failed!", vbCritical, "ALL Imports Failure"
-
End If
Thank you it worked perfectly
ADezii 8,834
Recognized Expert Expert
Glad it worked out for you.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: gwaddell |
last post by:
I have a stored procedure that is loading data into a global temp table.
Here is all the code for that stored procedure.
CREATE PROCEDURE
AS
SET NOCOUNT ON
BEGIN
|
by: user_5701 |
last post by:
Hello, I'm getting an error with a Docmd.Transferspreadsheet line of
code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel2000,
"tblTest", pathAndFilename, True
The above line...
|
by: Polly |
last post by:
I had a macro that ran a parameter query and created and opened an
Excel file with the system date as part of the file name, but I had to
change the file name by hand. So I converted the macro to...
|
by: aleksandra_83 |
last post by:
Hello,
I have searched all over google groups and internet, but I have not
found a solution to this problem that has worked. The solutions I found
helped me single out the line that is causing...
|
by: sara |
last post by:
I have a procedure to automate bringing several Excel files into our
Access tables, on a daily basis.
The problem is that if the user has a problem, and tries to run the
import again (maybe 3...
| |
by: SarahK |
last post by:
All,
I am trying to import a table from Excel, but I get the 3709 error,
search key not found. Any ideas? My TransferSpreadsheet method
statement is:
DoCmd.TransferSpreadsheet acImport, ,...
|
by: robert.waters |
last post by:
Hello,
When executing DoCmd.TransferSpreadsheet to an .xls file that's being
used as a datasource for a Word mail merge document, if that Word
document is currently open, the TransferSpreadsheet...
|
by: ineedahelp |
last post by:
Can anyone help me figure out why I continue to get a runtime error '3010' "TABLE qryMultiSelect ALREADY EXISTS'? Here is my code. thank you in advance for any help!!!
Private Sub...
|
by: Kosmos |
last post by:
Hey ya'll...I can't seem to figure out why I'm getting this error message, but it all started when I added the new line of code with the recSet5.AddNew --- when I ran the first line, the logic worked...
|
by: repath |
last post by:
I tried the code with automation:
For Each sheet In objWorkBook.sheets 'for each sheet in excel loop
Debug.Print "Imported sheet is :"; sheet.Name
DoCmd.TransferSpreadsheet acImport,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |