Connecting Tech Pros Worldwide Help | Site Map

Deleting temporary tables

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 2nd, 2006, 02:55 PM
john
Guest
 
Posts: n/a
Default Deleting temporary tables

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, 04:15 PM
Mark Reed
Guest
 
Posts: n/a
Default 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, 08:35 PM
pietlinden@hotmail.com
Guest
 
Posts: n/a
Default 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, 09:45 PM
Larry Linson
Guest
 
Posts: n/a
Default 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, 06:55 AM
john
Guest
 
Posts: n/a
Default 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
>>
>>
>
>

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.