I want a VBA code to make a query to show Equip with Top ActiveTime for each ModelID (from 1st table) based on TopN for each ModelID (from the 2nd table), I know i have to use QueryDef and Sql VBA but I can't figure how to write the code
Just and Example to illustrate
My 1st table is
EquipID | Equip | ActimeTime | ModelID |
---|---|---|---|
1 | DT1 | 10 | 1 |
2 | DT2 | 6 | 1 |
3 | DT3 | 13 | 1 |
4 | DT4 | 15 | 1 |
5 | DT5 | 16 | 2 |
6 | DT6 | 12 | 2 |
7 | DT7 | 6 | 2 |
8 | DT8 | 13 | 2 |
My 2nd Table is
ModelID | Model | TopN |
---|---|---|
1 | 775 | 3 |
2 | 789 | 2 |
So the query result should be like (Showing the Top 3 of 775 Model and the Top 2 of 789)
Equip | ActimeTime | Model |
---|---|---|
DT4 | 15 | 775 |
DT3 | 13 | 775 |
DT1 | 10 | 775 |
DT5 | 16 | 789 |
DT8 | 13 | 789 |
Thanks a lot in advance, I'm really stuck at this one and solving this will help me a lot in my project
[Table1][1] [1]: https://i.stack.imgur.com/geMca.png [Table2][2] [2]: https://i.stack.imgur.com/lMPDP.png [Query Result][3] [3]: https://i.stack.imgur.com/cGf6k.png