Automate import from excel or csv into Access

Anguscat

Board Regular
Joined
Jul 17, 2007
Messages
53
Does anyone know of an easy way to import other than the manual way of file-get external data-import.

I would like to be able to set something up that has a file location saved and when a new file is put in that directory I can just click a button and pull it into Access.

Thanks!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I'm not sure what happened, but for some reason. The code is not importing from the designated path. It is looking in my C: drive??
 
Upvote 0
This is the code that sets the search folder; did you change anything here?

Code:
    Const TOP_FOLDER = "H:\Test" 'adjust folder name to suit 
    Const ARCHIVE_FOLDER = "H:\Test\Imported" 'adjust folder name to suit

Denis
 
Upvote 0
I did, I changed it to a network path (maybe I can;t do that):

Const TOP_FOLDER = "\\Midp-sfs-004\analysis\2007data"

I think I found my error. When it gets to the code

DoCmd.TransferSpreadsheet acImport

I didn't specify the path, it must be defaulting to my C: drive
 
Upvote 0
I haven't tried using UNC naming for defining the import folder; maybe you need to use your mapped drive path instead.

Denis
 
Upvote 0
okay, I have everything working great and I notice that my code is appending the data instead of overlaying the data, I can run a delete query initially to fix this, but might the be a simple fix. Am I using the wrong command here:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, filenm, .FoundFiles(i), True


Thanks,
Bill
 
Upvote 0
Hi Bill, add this before the import line:

Code:
On Error Resume Next
DoCmd.RunSQL "DELETE * FROM " & filenm
On Error GoTo 0

I'm pretty sure that TransferSpreadsheet will append to existing tables, so you will need to delete the existing records first.

Denis
 
Upvote 0

Forum statistics

Threads
1,215,821
Messages
6,127,053
Members
449,356
Latest member
tstapleton67

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