Import specific columns in excel to access table using button (1 Viewer)

Hansi

New member
Local time
Tomorrow, 05:24
Joined
Jun 4, 2018
Messages
8
Hi! How can I import data from excel to existing table in access using button?

User is selecting the excel file from windows explorer and I want to program to enter only some columns to access table. And I am inserting date from form too.
 

Tieval

Still Clueless
Local time
Today, 23:24
Joined
Jun 26, 2015
Messages
475
Try googling DoCmd.TransferSpreadsheet , this will give you a good start.
 

isladogs

MVP / VIP
Local time
Today, 23:24
Joined
Jan 14, 2017
Messages
18,212
Alternatively, add the Excel spreadsheet as a linked table.
Run an append query to add the fields you want to your Access table.
This can be done from your button code.
Include the date field as part of your query setting the value to that on your form control
 

Hansi

New member
Local time
Tomorrow, 05:24
Joined
Jun 4, 2018
Messages
8
Isn't DoCmd.TransferSpreadsheet import all the fields? I don't want all and the columns that I want are not in order.
 

isladogs

MVP / VIP
Local time
Today, 23:24
Joined
Jan 14, 2017
Messages
18,212
That's one reason why I suggested the other approach.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:24
Joined
Feb 19, 2002
Messages
43,257
The TransferSpreadsheet method allows for linking or importing. Collin's suggestion to link gives you more flexibility since you can use append queries or even code if the formatting is really bad. The append query can select any or all columns and the column names don't even have to match. You can even sometimes change formats.

The one bad thing is that Access and Excel collude to determine the data types of each column and they examine only a small sampling of data so they frequently come up with the wrong answer. This is one of the things you can watch out for if you link the spreadsheet. You can examine the fields collection and see if any columns are defined as a numeric data type when you think they should be text and deal with the issue.
 

Users who are viewing this thread

Top Bottom