Hi All
So i am trying to generate a complex excel sheet from data from my database.
I have currently 4 complex queries (but the need for at least 2 more) some of which use the results of 1 to generate total lines for the sheet. Also as part of some of the queries i am doing currency conversions based on dates to get correct currency rates.
I have been slowly building my sheet a bit at a time and it was working until i added the 4th part to it. This is where i hit too many databases open issue. I know people like to see full bits of code but there is so much involved i am unsure its worth it in the post. The parts where the error is seen is:
What i am essentially doing is gathering a groups of groups of records which i intend to put on separate sheets, so i gather the group of records into a record set to loop through a filtered version of the recordset to put on each separate sheet.
When i do this i get the following output of databases used:
Before we start 226
After first record set is created 132
After second record set is created 38
After third record set is created 13
So if i uncomment the 4th record set creation lines it fails as expected as we only have 13 left at this point
I really wanted to do all of this with queries as initially i was gathering total values manually whilst i go through the first and third record sets to populate total values on the sheet.
I also want to total the total lines and put that on a separate sheet and have a query that does that. And there are requests for more information on the sheet.
So i know that i've probably not done this in the best way and i'm sure there is a better way (i've seen people talk about temporary tables but not sure whether thats something i should use or not)
I've attached the full VBA code to this to give more context about what i am doing as it might help. any help or pointers would be gratefully appreciated.
Kind regards
Glen
So i am trying to generate a complex excel sheet from data from my database.
I have currently 4 complex queries (but the need for at least 2 more) some of which use the results of 1 to generate total lines for the sheet. Also as part of some of the queries i am doing currency conversions based on dates to get correct currency rates.
I have been slowly building my sheet a bit at a time and it was working until i added the 4th part to it. This is where i hit too many databases open issue. I know people like to see full bits of code but there is so much involved i am unsure its worth it in the post. The parts where the error is seen is:
Code:
Debug.Print fOpenDatabaseCount
strLevel1SQL = Replace(Left(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel1").SQL, Len(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel1").SQL) - 3), "ORDER BY", "WHERE [FACT-Consignments].cons_albaran In (" & selectedAlbarans & ") ORDER BY")
Set level1RS = CurrentDb.OpenRecordset(strLevel1SQL)
Debug.Print fOpenDatabaseCount
strLevel1TotalLineSQL = Replace(Left(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel1TotalLine").SQL, Len(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel1TotalLine").SQL) - 3), "ORDER BY", "HAVING [FACT-Consignments].cons_albaran In (" & selectedAlbarans & ") ORDER BY")
Set level1TotalLineRS = CurrentDb.OpenRecordset(strLevel1TotalLineSQL)
Debug.Print fOpenDatabaseCount
strLevel2SQL = Replace(Left(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel2").SQL, Len(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel2").SQL) - 3), "WHERE ((([FACT-Deliveries].del_rejected_del_id) Is Null))", "WHERE [FACT-Deliveries].del_rejected_del_id) Is Null And [FACT-Consignments].cons_albaran In (" & selectedAlbarans & ") ")
Set level2RS = CurrentDb.OpenRecordset(strLevel2SQL)
Debug.Print fOpenDatabaseCount
' strLevel2TotalLineSQL = Replace(Left(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel2TotalLine").SQL, Len(CurrentDb.QueryDefs("qryReturnsExcelSheetsLevel2TotalLine").SQL) - 3), "ORDER BY", "HAVING [qryReturnsExcelSheetsLevel2].[Supplier Ref] In (" & selectedAlbarans & ") ORDER BY")
' Set level2TotalLineRS = CurrentDb.OpenRecordset(strLevel2TotalLineSQL)
What i am essentially doing is gathering a groups of groups of records which i intend to put on separate sheets, so i gather the group of records into a record set to loop through a filtered version of the recordset to put on each separate sheet.
When i do this i get the following output of databases used:
Before we start 226
After first record set is created 132
After second record set is created 38
After third record set is created 13
So if i uncomment the 4th record set creation lines it fails as expected as we only have 13 left at this point
I really wanted to do all of this with queries as initially i was gathering total values manually whilst i go through the first and third record sets to populate total values on the sheet.
I also want to total the total lines and put that on a separate sheet and have a query that does that. And there are requests for more information on the sheet.
So i know that i've probably not done this in the best way and i'm sure there is a better way (i've seen people talk about temporary tables but not sure whether thats something i should use or not)
I've attached the full VBA code to this to give more context about what i am doing as it might help. any help or pointers would be gratefully appreciated.
Kind regards
Glen
Attachments
Last edited: