Question: How can I transform data from columns to rows and auto-populate foreign keys using VBA from a spreadsheet import data source?
Scenario
I have a situation where I have to import data from a MS Excel spreadsheet into an Access DB.
The spreadsheet data is in a flat file format.
The DB destination table has the following one-to-many relationship where PK = primary key, FK = foreign key, Fld = field/column
tblDestination: PK, FK, Fld_A, Fld_B, Fld_C
In terms of the destination table (tblDestination) configuration, the import spreadsheet is populated in a format where R = record/row:
PK, FK, R1, R2, R3, R4……..R12
There are 12 known entries for each FK.
By that I mean for a given row in the spreadsheet, there are 12 columns in the spreadsheet that will become rows in the destination table (tblDestination). This will always be the case for this particular Parent/Child combination.
The PK in tblDestination is an Autonumber field so nothing will be imported in the DB.
Solution Objective
I would like to:
1. Import the spreadsheet into a temporary table (tblTempImport)
2. Run a VBA routine on the table which:
a. Transposes the data into proper format for tblDestination (i.e. columns > rows)
b. Assigns the correct FK for each row in tblDestination
I’ve never done anything like this before and was wondering if anyone has solved a similar problem.
Many thanks for your suggestions
Scenario
I have a situation where I have to import data from a MS Excel spreadsheet into an Access DB.
The spreadsheet data is in a flat file format.
The DB destination table has the following one-to-many relationship where PK = primary key, FK = foreign key, Fld = field/column
tblDestination: PK, FK, Fld_A, Fld_B, Fld_C
In terms of the destination table (tblDestination) configuration, the import spreadsheet is populated in a format where R = record/row:
PK, FK, R1, R2, R3, R4……..R12
There are 12 known entries for each FK.
By that I mean for a given row in the spreadsheet, there are 12 columns in the spreadsheet that will become rows in the destination table (tblDestination). This will always be the case for this particular Parent/Child combination.
The PK in tblDestination is an Autonumber field so nothing will be imported in the DB.
Solution Objective
I would like to:
1. Import the spreadsheet into a temporary table (tblTempImport)
2. Run a VBA routine on the table which:
a. Transposes the data into proper format for tblDestination (i.e. columns > rows)
b. Assigns the correct FK for each row in tblDestination
I’ve never done anything like this before and was wondering if anyone has solved a similar problem.
Many thanks for your suggestions