Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting records in a table using a form

Status
Not open for further replies.

montyb

Technical User
Sep 8, 2000
26
0
0
US
I am using a table to temporarily store records that can be accessed in a form to show data that has been recently entered (into a permanent table). I want the records to clear when the form is closed (or when a clear command button is pushed). What do I need to do? [sig][/sig]
 
Since this is a temporary table, I would think you could just run a delete query that removes all records from that table in the On Close event. If you create the query, you could call it from both the close event and the button push...

Hope that helps...
[sig]<p>Terry M. Hoey<br><a href=mailto:th3856@txmail.sbc.com>th3856@txmail.sbc.com</a><br><a href= > </a><br>Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?[/sig]
 
I think that will work. My next question is how do I call the delete query? I'm still green in VBA. I was going along the path of...

Private Sub Form_Close()
docmd.openQuery... but I don't think I necessarily want to open it. How do I call it to run?

Thanks for the help [sig][/sig]
 
Take a look at the Docmd.RunSQL. I think you would click on the &quot;...&quot; button next to the forms On Close event. This would bring you to the code designer for the event for that form. I would make it the following:
Code:
Private Sub Form_Close()
   'Turn Warning Messages off
   DoCmd.SetWarnings (False)
   'Delete all records from the Temp Table
   DoCmd.OpenQuery &quot;qryDeleteTemps&quot;, acViewNormal, acEdit
   'Turn Messages back On
   DoCmd.SetWarnings (True)
End Sub

Hope that does it...

[sig]<p>Terry M. Hoey<br><a href=mailto:th3856@txmail.sbc.com>th3856@txmail.sbc.com</a><br><a href= > </a><br>Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?[/sig]
 
Woops, use the code, ignore the first line of that response.
[sig]<p>Terry M. Hoey<br><a href=mailto:th3856@txmail.sbc.com>th3856@txmail.sbc.com</a><br><a href= > </a><br>Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top