Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How import certain Excel columns into table in Access

Posted on 2013-06-05
7
Medium Priority
?
2,320 Views
Last Modified: 2013-06-05
I need to find a way to import certain columns of an Excel file into an Access table.

Here are the specifics:

1) The Excel file will always be in a specific folder on the user's desktop named "Import Files".
2) There will be only one Excel file in the folder.
3) The data to import will always be in "Sheet1"
4) This may change but for example I need columns A, B, C, D, F, and G
5) The first column will hold the primary key field.
6) The name of the table the data is to import into is "tblImports"

The is one more challenge to this but I'll ask in it a separate topic once this topic has been resolved.
0
Comment
Question by:SteveL13
  • 4
  • 3
7 Comments
 
LVL 49

Expert Comment

by:Dale Fye
ID: 39223096
I generally use the TransferSpreadsheet method to import all of the fields into a staging table (tblStageExcelData), then I use a query to append only the fields I need into my destination table (tblImports).  This allows me to use the built in conversion functions to ensure that the data that ends up in my destination table is in the correct format.
0
 

Author Comment

by:SteveL13
ID: 39223223
I must be doing something wrong.  What is wrong with this?

DoCmd.TransferSpreadsheet acImport, 3, "tblTempImport", "C:\ImportFiles\ImportFile.xlsx", True

(I'm using Access 2010)
0
 
LVL 49

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 39223270
I don't see '3' being an option for the spreadsheet type argument.  Try:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "tblTempImport", "C:\ImportFiles\ImportFile.xlsx", True
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:SteveL13
ID: 39223295
That did work.  But a question...  will acSpreadsheetTypeExcel12 work for Access 2007 as well as 2010?
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 39223304
Yes.
0
 

Author Comment

by:SteveL13
ID: 39223324
Thank you very much.
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 39223434
welcome.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question