Link Access Database to Multiple Undefined excel worksheets in A FOLDER

jwb1012

Board Regular
Joined
Oct 17, 2016
Messages
167
Hell, I have a folder at the following link where we keep monthly summary reports of all orders placed - each month a new report for that month's orders is added. Is it possible to create an access database and link it to ALL EXCEL FILES within A FOLDER. As new reports are added to this folder, I would like it to be automatically added to the database without having to go into access and import a new table (this is what I am referring to in the title when I say "Undefined" - i.e. not yet created).

I am new to Access so any support would be very much appreciated.

File Location:
C:\Users\XXXXX\Desktop\Orders

Current files:
  1. Orders - Jan 2016
  2. Orders - Feb 2016
  3. Orders - Mar 2016
  4. Orders - Apr 2016
  5. Orders - May 2016
  6. Orders - June 2016
  7. Orders - July 2016
  8. Orders - Aug 2016
  9. Orders - Sep 2016
  10. Orders - Oct 2016
  11. Orders - Nov 2016
  12. Orders - Dec 2016

Future files:

  1. Orders - Jan 2017
  2. Orders - Feb 2017
  3. Orders - Mar 2017
  4. Orders - Apr 2017
  5. Orders - May 2017
  6. Orders - June 2017
  7. Orders - July 2017
  8. Orders - Aug 2017
  9. Orders - Sep 2017
  10. Orders - Oct 2017
  11. Orders - Nov 2017
  12. Orders - Dec 2017
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Here is what I have so far, but when I run the code nothing happens. :(

Any thoughts, insight, suggestions?? I would be forever grateful!


Code:
Option Explicit
 Function DoImport()
 Dim strPathFile As String, strFile As String, strPath As String
 Dim strTable As String
Dim blnHasFieldNames As BooleanblnHasFieldNames = True
 blnHasFieldNames = True

'Path to the folder that contains the EXCEL files
 strPath = "C:\Users\XXXXX\Desktop\Orders"

 ' Table which the data is imported into
strTable = "Table1"

 Do While Len(strFile) > 0
strPathFile = strPath & strFile
 strTable = Left(strFile, Len(strFile) - 4)
 DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
 strFile = Dir()
 Loop

 End Function
 
Last edited:
Upvote 0
You need to be clear on what it is you need. First you twice say link, then you say import a new table. Whichever it is you need, I'd say the author of those file names does not know that it's just bad form to use special characters or spaces (other than the underscore) anywhere. The likely reason that your code doesn't affect anything is that you don't pass anything to this function as a value for strFile and don't assign it within the function. If you were to step through it, I'd wager that when it executes Do While Len, it jumps to the end. This function also doesn't return anything to anywhere, so it might as well be a sub. I'm guessing you copied this from somewhere, intending to adapt it to your needs, but it's not going to work as is.

First, as noted: link or transfer data? Either way, you're going to need to iterate through all the files in a folder and perform the necessary action, and know what you want to do if this action has been done before with a particular file. Or you do so manually on a monthly basis with Get External Data from the Access ribbon.
 
Last edited:
Upvote 0
Personally I'd think it preferable to import (not link) the data. And not have lots of tables - one table.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top