Splitting Single Table Record into up to 20 Individual Records (1 Viewer)

dbabaracus

New member
Local time
Yesterday, 19:52
Joined
Jul 26, 2017
Messages
4
I'm building out a database to handle submissions for an art show. Users submit information for up to 20 pieces of art. The export from the webform is a .csv that resembles this:

UserID, UserName, Title1, Height1, Width1, Price1, Title2, Height2, Width2, Price2,[...], Title20, Height20, Width20, Price20

What I'd like to do is paste that data into a table and somehow translate it into separate rows/records for each piece.

Like so:

User001, Billy Billson, Untitled #1, 12, 10, $5, Untitled #2, 23, 15, $10...

Translated to:

User001, Billy Billson, Untitled #1, 12, 10, $5
User001, Billy Billson, Untitled #2, 23, 15, $10

I've seen solutions for similar problems where you use a query with unlinked tables and have each field as a series of nested IIf functions. But I don't think Access (or I) can handle 20 nested IIfs. Is there a good way to go about this?

The actual fields for each piece are:

Title
Medium
Length (number)
Length Unit ("FT" or "IN)
Height
Height Unit
Width
Width Unit
Price
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 00:52
Joined
Jul 9, 2003
Messages
16,282
How you go about it will depend on how often you are going to do this. A one off, every week, month, year... Also how many records are there in the comma separated value file (CSV) and how many columns you say 20, will it always be 20?

Q1) how often
Q2) how many records
Q3) how many columns
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 00:52
Joined
Jul 9, 2003
Messages
16,282
A secondary issue is your assumption that you will put everything into a single table:-

User001, Billy Billson, Untitled #1, 12, 10, $5
User001, Billy Billson, Untitled #2, 23, 15, $10

Not recommended. really you should have three tables there's the first one:-

tblUser:-
ID, --- Name
001, Billy Billson
002, Don De Mouth

And then your picture table:-
tblPicture

ID Title ------ H -- W -- £
1000, Untitled #1, 12, 10, $5
1001, Untitled #2, 23, 15, $10
1100, Untitled #3, 15, 20, $500
1527, Untitled #4, 29, 35, $100

Table user picture combined
tblInventory

UserID -- Pic ID
001, ------ 1000
001, ------ 1001
002, ------ 1100
002, ------ 1527
 

plog

Banishment Pending
Local time
Yesterday, 18:52
Joined
May 11, 2011
Messages
11,646
There's 2 methods to achieve this. Both start with you importing your .csv data into a staging table. Let's call it 'tblStage' and the table where you want this table to end up at 'tblFinal'.

Method 1 - APPEND queries. You build 20 APPEND queries using tblStage to write into tblFinal. Each query would work on a different set of Title/Height/Width/Price values. Query1 would append Title1, Hieght1, etc. Query2 would append Title2, Height2, etc. RUn 20 queries and your data is moved.

Method 2 - VBA function. You build a function to read tblStage into a Recordset and then loop through every record writing a dynamic APPEND query for each one so that each record gets appended to tblFinal. Run the function once and your data is moved.

Hint, method2 is preferrable.
 

Users who are viewing this thread

Top Bottom