Pacific1,
Further to PMs, here is last attempt to work with Transaction level. There are 21 transactions, with a Total Sum of QTY = 9200.
You will notice that I added 2 fields to tblUsedBoxes --FilledAt and ItemName.
I have attached files for the source code for these new functions, and the latest copy of the database. I took a copy of your
database and have added the functions, some queries. You'll run the code from FillBoxesTrans.
I created another version of FillBoxes called FillBoxesTrans, and created a new Function called PutItemsIntoBoxTrans
These are included in the attached file. You replace the function FillBoxes with FillBoxesTrans, You replace PutItemsIntoBox
with PutItemsIntoBoxTrans. Then you run the code from FillBoxesTrans
Transaction table values being used:
Transaction ID |
QTY |
Product Code |
Details ID |
Transaction Note |
1 |
100 |
PP002 |
3 |
|
2 |
100 |
PZ004 |
3 |
|
3 |
100 |
PZ023 |
3 |
|
4 |
100 |
PZ103 |
3 |
|
5 |
100 |
PZ100 |
3 |
|
6 |
100 |
PP036 |
3 |
|
7 |
100 |
PZ115 |
3 |
|
8 |
100 |
PP031 |
3 |
|
9 |
100 |
PZ178 |
3 |
|
10 |
100 |
PZ179 |
3 |
|
11 |
100 |
PZ185 |
3 |
|
12 |
100 |
PZ189 |
3 |
|
13 |
1900 |
PP002 |
4 |
|
14 |
1900 |
PP008 |
4 |
|
15 |
3400 |
PP009 |
4 |
|
16 |
200 |
PP002 |
5 |
|
17 |
100 |
PZ023 |
5 |
|
18 |
100 |
PP033 |
5 |
|
19 |
100 |
PP043 |
5 |
|
20 |
200 |
PP061 |
5 |
|
21 |
100 |
PP064 |
5 |
|
Here is the tblUsedBoxes. ItemIDFK is the transaction id, ItemName is the [Details Id] & " - " & [Prod Id]
and is an attempt to show you the Product and details going into which Box.
BoxIdFK is the Box containing this record (transaction/quantity)
It shows the allocation across 23 boxes
BoxIdFK |
UsedBoxId |
ItemIDFK |
ItemQty |
Transaction ID |
FilledAt |
ItemName |
1 |
|
1 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 223 |
1 |
|
2 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 211 |
1 |
|
3 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 218 |
1 |
|
4 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 263 |
2 |
|
5 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 270 |
2 |
|
6 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 236 |
2 |
|
7 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 279 |
2 |
|
8 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 240 |
3 |
|
9 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 280 |
3 |
|
10 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 281 |
3 |
|
11 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 285 |
3 |
|
12 |
100 |
0 |
01/12/2014 8:04:37 PM |
3 - 289 |
4 |
|
13 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 223 |
5 |
|
13 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 223 |
6 |
|
13 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 223 |
7 |
|
13 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 223 |
8 |
|
13 |
300 |
0 |
01/12/2014 8:04:37 PM |
4 - 223 |
9 |
|
14 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 225 |
10 |
|
14 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 225 |
11 |
|
14 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 225 |
12 |
|
14 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 225 |
13 |
|
14 |
300 |
0 |
01/12/2014 8:04:37 PM |
4 - 225 |
14 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
15 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
16 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
17 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
18 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
19 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
20 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
21 |
|
15 |
400 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
22 |
|
15 |
200 |
0 |
01/12/2014 8:04:37 PM |
4 - 226 |
22 |
|
16 |
200 |
0 |
01/12/2014 8:04:37 PM |
5 - 223 |
8 |
|
17 |
100 |
0 |
01/12/2014 8:04:37 PM |
5 - 218 |
13 |
|
18 |
100 |
0 |
01/12/2014 8:04:37 PM |
5 - 232 |
23 |
|
19 |
100 |
0 |
01/12/2014 8:04:37 PM |
5 - 242 |
23 |
|
20 |
200 |
0 |
01/12/2014 8:04:37 PM |
5 - 244 |
23 |
|
21 |
100 |
0 |
01/12/2014 8:04:37 PM |
5 - 247 |
This is the log of activity as shown in immediate window.
Code:
Best guess for Total Boxes Needed for Shipping 23
processing 100 units of Item 1
findspace value is 0
++ Added 100 units of Item 1 name 3 - 223 to Box 1
Finished with Item 1
processing 100 units of Item 2
findspace value is 1
working Boxno 2
findspace value is 1
++ Added 100 units of Item 2 name 3 - 211 to Box 1
Finished with Item 2
processing 100 units of Item 3
findspace value is 1
working Boxno 2
findspace value is 1
++ Added 100 units of Item 3 name 3 - 218 to Box 1
Finished with Item 3
processing 100 units of Item 4
findspace value is 1
working Boxno 2
findspace value is 1
++ Added 100 units of Item 4 name 3 - 263 to Box 1
Finished with Item 4
processing 100 units of Item 5
findspace value is 0
++ Added 100 units of Item 5 name 3 - 270 to Box 2
Finished with Item 5
processing 100 units of Item 6
findspace value is 2
working Boxno 3
findspace value is 2
++ Added 100 units of Item 6 name 3 - 236 to Box 2
Finished with Item 6
processing 100 units of Item 7
findspace value is 2
working Boxno 3
findspace value is 2
++ Added 100 units of Item 7 name 3 - 279 to Box 2
Finished with Item 7
processing 100 units of Item 8
findspace value is 2
working Boxno 3
findspace value is 2
++ Added 100 units of Item 8 name 3 - 240 to Box 2
Finished with Item 8
processing 100 units of Item 9
findspace value is 0
++ Added 100 units of Item 9 name 3 - 280 to Box 3
Finished with Item 9
processing 100 units of Item 10
findspace value is 3
working Boxno 4
findspace value is 3
++ Added 100 units of Item 10 name 3 - 281 to Box 3
Finished with Item 10
processing 100 units of Item 11
findspace value is 3
working Boxno 4
findspace value is 3
++ Added 100 units of Item 11 name 3 - 285 to Box 3
Finished with Item 11
processing 100 units of Item 12
findspace value is 3
working Boxno 4
findspace value is 3
++ Added 100 units of Item 12 name 3 - 289 to Box 3
Finished with Item 12
processing 1900 units of Item 13
++ Added 400 units of Item 13 name 4 - 223 to Box 4
Qty of this Item 13 to process is now 1500
Box being used is 5
++ Added 400 units of Item 13 name 4 - 223 to Box 5
Qty of this Item 13 to process is now 1100
Box being used is 6
++ Added 400 units of Item 13 name 4 - 223 to Box 6
Qty of this Item 13 to process is now 700
Box being used is 7
++ Added 400 units of Item 13 name 4 - 223 to Box 7
Qty of this Item 13 to process is now 300
Box being used is 8
findspace value is 0
++ Added 300 units of Item 13 name 4 - 223 to Box 8
Finished with Item 13
processing 1900 units of Item 14
++ Added 400 units of Item 14 name 4 - 225 to Box 9
Qty of this Item 14 to process is now 1500
Box being used is 10
++ Added 400 units of Item 14 name 4 - 225 to Box 10
Qty of this Item 14 to process is now 1100
Box being used is 11
++ Added 400 units of Item 14 name 4 - 225 to Box 11
Qty of this Item 14 to process is now 700
Box being used is 12
++ Added 400 units of Item 14 name 4 - 225 to Box 12
Qty of this Item 14 to process is now 300
Box being used is 13
findspace value is 0
++ Added 300 units of Item 14 name 4 - 225 to Box 13
Finished with Item 14
processing 3400 units of Item 15
++ Added 400 units of Item 15 name 4 - 226 to Box 14
Qty of this Item 15 to process is now 3000
Box being used is 15
++ Added 400 units of Item 15 name 4 - 226 to Box 15
Qty of this Item 15 to process is now 2600
Box being used is 16
++ Added 400 units of Item 15 name 4 - 226 to Box 16
Qty of this Item 15 to process is now 2200
Box being used is 17
++ Added 400 units of Item 15 name 4 - 226 to Box 17
Qty of this Item 15 to process is now 1800
Box being used is 18
++ Added 400 units of Item 15 name 4 - 226 to Box 18
Qty of this Item 15 to process is now 1400
Box being used is 19
++ Added 400 units of Item 15 name 4 - 226 to Box 19
Qty of this Item 15 to process is now 1000
Box being used is 20
++ Added 400 units of Item 15 name 4 - 226 to Box 20
Qty of this Item 15 to process is now 600
Box being used is 21
++ Added 400 units of Item 15 name 4 - 226 to Box 21
Qty of this Item 15 to process is now 200
Box being used is 22
findspace value is 0
++ Added 200 units of Item 15 name 4 - 226 to Box 22
Finished with Item 15
processing 200 units of Item 16
findspace value is 22
working Boxno 23
findspace value is 22
++ Added 200 units of Item 16 name 5 - 223 to Box 22
Finished with Item 16
processing 100 units of Item 17
findspace value is 8
working Boxno 23
findspace value is 8
++ Added 100 units of Item 17 name 5 - 218 to Box 8
Finished with Item 17
processing 100 units of Item 18
findspace value is 13
working Boxno 23
findspace value is 13
++ Added 100 units of Item 18 name 5 - 232 to Box 13
Finished with Item 18
processing 100 units of Item 19
findspace value is 0
++ Added 100 units of Item 19 name 5 - 242 to Box 23
Finished with Item 19
processing 200 units of Item 20
findspace value is 23
working Boxno 24
findspace value is 23
++ Added 200 units of Item 20 name 5 - 244 to Box 23
Finished with Item 20
processing 100 units of Item 21
findspace value is 23
working Boxno 24
findspace value is 23
++ Added 100 units of Item 21 name 5 - 247 to Box 23
Finished with Item 21
Query2 is just another presentation of the contents of tblUsedBoxes.
HIghlighting the [Detail Id]
Query2 SQL
Code:
SELECT tblUsedBoxes.BoxIdFK, tblUsedBoxes.ItemName, tblUsedBoxes.ItemIDFK
, Sum(tblUsedBoxes.ItemQty) AS SumOfItemQty, Left([ItemName],1) AS DetailId
FROM tblUsedBoxes
GROUP BY tblUsedBoxes.BoxIdFK, tblUsedBoxes.ItemName, tblUsedBoxes.ItemIDFK, Left([ItemName],1);
BoxIdFK |
ItemName |
ItemIDFK |
SumOfItemQty |
DetailId |
1 |
3 - 211 |
2 |
100 |
3 |
1 |
3 - 218 |
3 |
100 |
3 |
1 |
3 - 223 |
1 |
100 |
3 |
1 |
3 - 263 |
4 |
100 |
3 |
2 |
3 - 236 |
6 |
100 |
3 |
2 |
3 - 240 |
8 |
100 |
3 |
2 |
3 - 270 |
5 |
100 |
3 |
2 |
3 - 279 |
7 |
100 |
3 |
3 |
3 - 280 |
9 |
100 |
3 |
3 |
3 - 281 |
10 |
100 |
3 |
3 |
3 - 285 |
11 |
100 |
3 |
3 |
3 - 289 |
12 |
100 |
3 |
4 |
4 - 223 |
13 |
400 |
4 |
5 |
4 - 223 |
13 |
400 |
4 |
6 |
4 - 223 |
13 |
400 |
4 |
7 |
4 - 223 |
13 |
400 |
4 |
8 |
4 - 223 |
13 |
300 |
4 |
8 |
5 - 218 |
17 |
100 |
5 |
9 |
4 - 225 |
14 |
400 |
4 |
10 |
4 - 225 |
14 |
400 |
4 |
11 |
4 - 225 |
14 |
400 |
4 |
12 |
4 - 225 |
14 |
400 |
4 |
13 |
4 - 225 |
14 |
300 |
4 |
13 |
5 - 232 |
18 |
100 |
5 |
14 |
4 - 226 |
15 |
400 |
4 |
15 |
4 - 226 |
15 |
400 |
4 |
16 |
4 - 226 |
15 |
400 |
4 |
17 |
4 - 226 |
15 |
400 |
4 |
18 |
4 - 226 |
15 |
400 |
4 |
19 |
4 - 226 |
15 |
400 |
4 |
20 |
4 - 226 |
15 |
400 |
4 |
21 |
4 - 226 |
15 |
400 |
4 |
22 |
4 - 226 |
15 |
200 |
4 |
22 |
5 - 223 |
16 |
200 |
5 |
23 |
5 - 242 |
19 |
100 |
5 |
23 |
5 - 244 |
20 |
200 |
5 |
23 |
5 - 247 |
21 |
100 |
5 |