Import Spredsheet Question

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Hi all,

I am importing a spreadsheet with the following code:

Code:
Sub ImportExcel()
Dim strXls As String
strXls = "UNC Address Removed For Post"
DoCmd.TransferSpreadsheet acImport, , "tblStockImport", _
    strXls, True, "Delivery Volumes!"
 
End Sub

This works fine, however, the issue is that my import needs to be ran daily, after the import spreadsheet has been updated.

Using the above, all data in the spreadsheet becomes duplicated. Is there any way to import only 'new' data into the table? Essentially, everyday the target spreadhseet will have one additional row added. Ideally that is the only row i wish to import on a day to day basis.

Currently I am deleteing the table, creating a table and then importing. This is annoying and time consuming.

Any help will be great.

Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You could import into a temporary table and then run an append query to only add the new data to the existing table.

Then you can delete the temporary table

That could all be done in code.

You could actually have code to delete all records in the destination table before the import.
Code:
Application.DisplayAlerts = False ' optional
DoCmd.RunSQL "DELETE *.* FROM tblStockImport"
Application.DisplayAlerts = True
 
strXls = "UNC Address Removed For Post"
DoCmd.TransferSpreadsheet acImport, , "tblStockImport", _
    strXls, True, "Delivery Volumes!"
 
Upvote 0
My first choice on a solution would be to follow Norie's advice. This is what I have done in the past. However, if you don't wish to be bothered, an alternative to this is to link your Excel table to Access and then your Access data would be updated every time your Excel table is updated.

Alan
 
Upvote 0
Cheers guys. I will most probably follow Norie's suggestion - I had started thinking along those lines myself. Just out of curiosity alan, how would I go about linking my excel spreadsheet to my database?

Thanks

P.S. for some reason Application.DisplayAlerts = False brings up an error for me, I am having to use DoCmd.SetWarnings False for some strange reason.
 
Last edited:
Upvote 0
Jameo

Oops, my mistake.

DisplayAlerts is Excel not Access.:oops:

I did say it was optional though.:)
 
Upvote 0
Just out of curiosity alan, how would I go about linking my excel spreadsheet to my database?
Which version of Access are you using?
In 2003 or earlier, just right click and select "Link" instead of "Import".
In 2007 and higher, click on the Excel icon in the External Data ribbon, and select the "Link to the data source by creating a linked table" option.
P.S. for some reason Application.DisplayAlerts = False brings up an error for me, I am having to use DoCmd.SetWarnings False for some strange reason.
Application.DisplayAlerts = False is Excel VBA syntax.
To do the same thing in Access VBA, you need to use DoCmd.SetWarnings False instead.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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