airforceone
Board Regular
- Joined
- Feb 14, 2022
- Messages
- 201
- Office Version
- 2019
- 2016
- Platform
- Windows
I have the following details from my Database
and here is the summary of the code performing the query, the code works well and accurate my only problem is it takes forever to finish the reports spanning from 2001 to date of this writing...
any idea is highly appreciated to make the performance of the code a bit faster (ie. other union way, using temp Table prior processing, etc....) I believe sharing my Database would help in crafting the code but due to the nature of the records I could not my apology for that...
TABLE | # OF RECORDS | FIELDS / COLUMNS |
tbl_A | 5900 | 50 |
tbl_B | 6000 | 40 |
tbl_C | 7000 | 60 |
tbl_D | 8000 | 14 |
and here is the summary of the code performing the query, the code works well and accurate my only problem is it takes forever to finish the reports spanning from 2001 to date of this writing...
any idea is highly appreciated to make the performance of the code a bit faster (ie. other union way, using temp Table prior processing, etc....) I believe sharing my Database would help in crafting the code but due to the nature of the records I could not my apology for that...
Code:
SQLScript01 = " SELECT
[tbl_A].[REGI NUMBER],{ OTHER FIELDS UNDER tbl_A },
[tbl_B].[REGI NUMBER],{ OTHER FIELDS UNDER tbl_B },
[tbl_C].[REGI NUMBER],{ OTHER FIELDS UNDER tbl_C },
[tbl_D].[REGI NUMBER],{ OTHER FIELDS UNDER tbl_D },"
SQLTable = "newREPORT"
SQLFrom = " FROM ((tbl_A LEFT JOIN tbl_B ON tbl_A.[REGI NUMBER] = tbl_B.[REGI NUMBER]) LEFT JOIN tbl_C ON tbl_A.[REGI NUMBER] = tbl_C.[REGI NUMBER]) LEFT JOIN ref_Details ON tbl_A.[REGI NUMBER] = tbl_D.[REGI NUMBER]"
SQLWhere = "WHERE (YEAR(tbl_A.[DATE REGISTERED]) >= " & YEAR_FROM & " AND YEAR(tbl_A.[DATE REGISTERED]) <= " & YEAR_TO & ")"
SQLAnd = " AND UCase([CLASS TYPE]) <> 'VOLUNTARY'"
SQLOrder = " ORDER BY tbl_A.NATURE, tbl_A.[DATE REGISTERED];"
EySQL = SQLScript01 & " INTO " & SQLTable & SQLFrom & SQLWhere & SQLAnd & SQLOrder
DoCmd.RunSQL EySQL