ChuckRobert
Board Regular
- Joined
- Feb 26, 2009
- Messages
- 64
I am trying to save the results of a query called qry_RosterBase to a temporary table called tbl_TempForRoster. The query formats data from the Personnel Table for the Roster report. I am hoping that the numerous queries required to generate the Roster report will run faster by referencing tbl_TempForRoster when it opens, instead of qry_RosterBase. The code below is activated with a button click. If I comment out the final line “DoCmd.DeleteObjectacTable, strTable”, I can see that the code does make the temp table, and copy all data from the query to the temp table, but only after clicking the button a second time. If I do not comment out the last line, the temp table is never built. I also tried to get just some of the query by changing “Select * to “Select qry_RosterBase.Name, qry_RosterBase.Assignment….. In this case it would copy it over on the second click if only one field is entered in the select statement, but not with more than one. Suggestions?
<o></o>
Code:
[COLOR=black][FONT=Times New Roman]Dim strSQL As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Dim strTable As String<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]strTable = "tbl_TempForRoster"<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]'Delete the table if it exists<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]DoCmd.DeleteObject acTable, strTable<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]strSQL = "Select * INTO " & strTable & "FROM qry_RosterBase "<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]CurrentDb.Execute strSQL<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]'Do required actions…, then delete temp table<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]<o:p> </o:p>[/FONT][/COLOR][COLOR=black][FONT=Times New Roman]DoCmd.DeleteObject acTable, strTable[/FONT][/COLOR]
Last edited: