Connecting Tech Pros Worldwide Help | Site Map

Deleting temporary tables

  #1  
Old September 2nd, 2006, 03:55 PM
john
Guest
 
Posts: n/a
When leaving the main menu form I want to delete some temporary tables. The
following code on the form's close works: DoCmd.DeleteObject acTable,
"tmpEnvelop". But is it possible to change it so that it deletes all tables
starting with tmp?
Thanks,
john


  #2  
Old September 2nd, 2006, 05:15 PM
Mark Reed
Guest
 
Posts: n/a

re: Deleting temporary tables


How I would do this is to create a new module and paste the following:

'**************Code Start***************
Sub Delete_Temp_Tables()

Dim Rst As DAO.Recordset
Dim StrSql As String

'Create a recordset containing table names beginning with 'TMP'
StrSql = "SELECT MSysObjects.Name " & _
"FROM MSysObjects " & _
"WHERE (((MSysObjects.ParentId) = 251658241)) " & _
"GROUP BY MSysObjects.Name " & _
"HAVING (((MSysObjects.Name) Like 'tmp*'));"

Set Rst = CurrentDb.OpenRecordset(StrSql, , dbReadOnly)

With Rst
Do While Not .EOF
DoCmd.DeleteObject acTable, !Name
.MoveNext
Loop
End With

Rst.Close
End Sub
'**************Code End***************

Then on the 'Unload' event of your main menu form, simply enter:
'Delete_Temp_Tables' without the quotes.

Hope this helps,

Mark


"john" <john@test.comwrote in message
news:eZqdnT_yp6v9AGTZRVnytQ@casema.nl...
Quote:
When leaving the main menu form I want to delete some temporary tables.
The following code on the form's close works: DoCmd.DeleteObject acTable,
"tmpEnvelop". But is it possible to change it so that it deletes all
tables starting with tmp?
Thanks,
john
>
>

  #3  
Old September 2nd, 2006, 09:35 PM
pietlinden@hotmail.com
Guest
 
Posts: n/a

re: Deleting temporary tables


why would you delete the temp tables entirely? Why not just truncate
them all? or even just put them in an external DB and then delete the
external DB when you're done with it?

  #4  
Old September 2nd, 2006, 10:45 PM
Larry Linson
Guest
 
Posts: n/a

re: Deleting temporary tables


"john" <john@test.comwrote
Quote:
When leaving the main menu form I
want to delete some temporary tables.
. . .
But is it possible to change it so that
it deletes all tables starting with tmp?
You can avoid the need for frequent Compact and Repair if you'll define your
temporary Tables in a temporary Database. There's an example at MVP Tony
Toews' site, http://www.granite.ab.ca/accsmstr.htm. Then when you are done,
you unlink, and delete the entire temporary Database.

Larry Linson
Microsoft Access MVP


  #5  
Old September 3rd, 2006, 07:55 AM
john
Guest
 
Posts: n/a

re: Deleting temporary tables


Thans Mark and others,
Didn't know you could query on table names like that.
john

"Mark Reed" <mark.reed75@ntlworld.comschreef in bericht
news:ZqiKg.8511$H11.2629@newsfe7-win.ntli.net...
Quote:
How I would do this is to create a new module and paste the following:
>
'**************Code Start***************
Sub Delete_Temp_Tables()
>
Dim Rst As DAO.Recordset
Dim StrSql As String
>
'Create a recordset containing table names beginning with 'TMP'
StrSql = "SELECT MSysObjects.Name " & _
"FROM MSysObjects " & _
"WHERE (((MSysObjects.ParentId) = 251658241)) " & _
"GROUP BY MSysObjects.Name " & _
"HAVING (((MSysObjects.Name) Like 'tmp*'));"
>
Set Rst = CurrentDb.OpenRecordset(StrSql, , dbReadOnly)
>
With Rst
Do While Not .EOF
DoCmd.DeleteObject acTable, !Name
.MoveNext
Loop
End With
>
Rst.Close
End Sub
'**************Code End***************
>
Then on the 'Unload' event of your main menu form, simply enter:
'Delete_Temp_Tables' without the quotes.
>
Hope this helps,
>
Mark
>
>
"john" <john@test.comwrote in message
news:eZqdnT_yp6v9AGTZRVnytQ@casema.nl...
Quote:
>When leaving the main menu form I want to delete some temporary tables.
>The following code on the form's close works: DoCmd.DeleteObject acTable,
>"tmpEnvelop". But is it possible to change it so that it deletes all
>tables starting with tmp?
>Thanks,
>john
>>
>>
>
>

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Efficient temporary tables Randy Harris answers 5 November 13th, 2005 07:31 AM
Temporary Tables. Where will they be created Mike Ridley answers 4 November 12th, 2005 11:42 PM
Temporary Tables. Where will they be created Mike Ridley answers 3 November 12th, 2005 10:33 PM
Does anyone have experience with the efficiency of global temporary tables? Chuck Crews answers 2 November 12th, 2005 09:43 AM