Ok I am using Access 2013 and have a continuous form using a flat table with the following fields:
OrderDate \ Ref \ ItemSize1 \ ItemSize 2 \ ItemSize 3 \ Qty 1 \ Qty 2 \ Qty 3
So eg data would look this:
09/06/15 \ PO123 \ ABC_S \ ABC_M \ ABC_L \ 2 \ 6 \ 8
09/06/15 \ PO123 \ XYZ_8 \ XYZ_10 \ XYZ_12 \ 3 \ 2 \ 7
However, I'm building a file for export that is needed in this format;
OrderDate \ Ref \ Item \ Qty
So the result data would look like this:
09/06/15 \ PO123 \ ABC_S \ 2
09/06/15 \ PO123 \ ABC_M \ 6
09/06/12 \ PO123 \ ABC_L \ 8
and so on.... Points to note:
Item Size 1 uses the qty from qty 1, item size 2 uses qty etc
I am only interested where items sizes have a qty. So if ItemSize 2 had no qty in Qty 2, I would need to miss it out
I have tried a Union query but for some reason it does not sort the size. The result file needs to have the items in order of size (ItemSize1, ItemSize2 etc)
What other way is there in Access to achieve this?
Thanks for any help.
Michael
I totally agree with krish, your solution is to make the data structure more resilient.
The real Solution: (Can be improved a lot)
First create the two tables,
Products
andInvoice
.Now the relationship between
Products
andInvoice
is One to Many, where one product can have many Invoices. Example, one Tee Shirt for one sizes/color could have many orders.Now the Products table will have the information of the products that you have available in your Database. Some sample would be.
Now the Invoice table should have the order for a particular product of particular size.
Now, once the data is transformed into the right structure, your Query would simply be.
Your result set would be,
Now, you should be able to get your head around, how simple data restructuring could make your queries so simple and easy to implement.
The temporary fix
Although it pains for me to tell you you should restructure your tables, does not mean that you cannot achieve what you want. Although the solution would work, and might even seem OK. It actually is not. There is too much memory involved, efficiency is poor. You create and drop records, constantly upsize your DB. so many disadvantages, but to hold things together.
Now the reason I have used VBA as opposed to luk2302's UNION query is because, with a little modification, the above query could actually be used to transform your flat table data into the structure you should have.
So have a think about it, I am sure you will never ever regret it. Good luck !