Close a form and delete the coressponding table

P

Phil

Hi,

I have 2 forms (A and B). There is a button in Form A to
open form B based on the job ID. Both form A and B are
generated from 2 different tables (A and B). After the
user finishes and closes the form B, I would like to have
Access automatically delete the table B. I put a code to
delete the table B on the Close event of form B but it did
not work because of the table B is in use. My guess is
that I need to close the form B completely in order to
unlock the table B and then I can delete the table B.
However, I have no idea how to trigger the delete action
after the form B is completely closed.

Which form and event should I put my code to close the
form B and delete the table B?

Thank you.
 
S

Steve Schapel

Phil,

I haven't tried it out, but it may work to use the form's Unload event
to do...
Me.Recordsource = ""
That way, table B is not in use any more by the time the form's Close
event comes around, and therefore the deletion of the table might
work?

- Steve Schapel, Microsoft Access MVP
 
G

Guest

Steve, Thank you so much. It works fine. I just change
it a little bit and put it under close event as follows:

me.recordsource = ""
docmd. deleteojbect..
docmd.close

Thank you.
 
S

Steve Schapel

Phil,

I can't see that DoCmd.Close is a good idea here. I mean, this code
is on the Close event of the form, eh? So, it's closing already. So
what are you trying to close?

- Steve Schapel, Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top