Reputation: 11
I'm trying to import a table from access database to other access database. But I don't want to import exactly, I have diferents fields
Courses Table 1
------------------------------
id | name | cost | other_field
------------------------------
1 | C012 | 250 | data
Courses Table 2
------------------------------
id | name | cost
------------------------------
1 | C012 | 250
I have all data into Courses 1 and I want to import this table to another table, but just some fields.
Can you help me? Thanks.
Upvotes: 0
Views: 56
Reputation: 1485
Link to Table1
in OtherAccessDb
:
DoCmd.TransferDatabase acLink, "Microsoft Access", "C\:Path\OtherAccessDb.accdb", acTable, "Table1", Table1
Now Pass the data. If you have created Table2
, Use SQL statement to insert to it data from Table1
:
DoCmd.Execuet "INSERT INTO Table2 (id, name, cost) SELECT id, name, cost FROM Table1"
If you have not created Table2
, Use SQL statement to create it, insert to it data from Table1
:
DoCmd.Execuet "SELECT INTO Table2 id, name, cost FROM Table1
If you don't need the link to Table1
for other use, it is recommended you remove it:
CurrentDb.TableDefs.Delete "Table1"
Note: this answer displays the process using VBA code. If it is a one time job, you can create a link, and a SQL query using the Access ribbon.
Upvotes: 2