illusionek
Registered User.
- Local time
- Today, 02:24
- Joined
- Dec 31, 2013
- Messages
- 92
Hi Guys,
I am using below code to import various Excel spreadsheets into Access. However every now and again below code goes into error, usually because there is no ‘toimport’ range in the Excel file.
So I would like to use On Resume Next, so it can import all other files. But in order to do it, I need also to be able to somehow capture information about all files that went into error, so I can fix them.
I would like to create like an ‘error log’ and I would like Access to update it with information about all the files that were not uploaded + error message + date/time.
Ideally I would like it to be in Excel file. I tried to use DoCmd.TransferSpreadsheet but it does not do what I need.
So I would be grateful for any help I can get.
I am using below code to import various Excel spreadsheets into Access. However every now and again below code goes into error, usually because there is no ‘toimport’ range in the Excel file.
So I would like to use On Resume Next, so it can import all other files. But in order to do it, I need also to be able to somehow capture information about all files that went into error, so I can fix them.
I would like to create like an ‘error log’ and I would like Access to update it with information about all the files that were not uploaded + error message + date/time.
Ideally I would like it to be in Excel file. I tried to use DoCmd.TransferSpreadsheet but it does not do what I need.
So I would be grateful for any help I can get.
Code:
Function import()
Dim strFile As String
DoCmd.SetWarnings False
' Set file directory for files to be imported
strPath = "C:\test\"
' Tell it to import all Excel files from the file directory
strFile = Dir(strPath & "*.xlsx*")
' Start loop
Do While strFile <> ""
' Import file
DoCmd.TransferSpreadsheet transfertype:=acImport, tablename:="TestTable", FileName:=strPath & strFile, HasFieldNames:=False, Range:="toimport"
' Loop to next file in directory
strFile = Dir
Loop
End Function