Run the Delete Query on Exit?

J

J.Bennett

I have a database that is used to provide quotes for storage buildings. If
the customer wants to actually purchase the building, then the user proceeds
with entering the customers name, address, etc. The querry I have set up
deletes all records that do not have either a first name or last name. It
all works exactly as I want.

Is there a way to run this delete query upon exiting the database? I would
prefer the "Are you really sure you want to delete these... or whatever it
says..." message box to not pop up.

Any help would be appreciated.
 
C

Chris O'C via AccessMonster.com

Have your startup form open a hidden form that remains open while the db app
is open. In the close event of this hidden form, put this code:

Dim db As Database

Set db = CurrentDb
db.Execute "nameofdeletequery", dbFailOnError
Set db = Nothing

When the db closes this form will close, executing the code in the close
event, which runs your delete query. The user won't see it unless there's a
problem. If there's a problem your error handler will tell the user what's
wrong and not delete any rows. Otherwise, completely silent.

Chris
Microsoft MVP
 
B

bcap

Of course, if the user "exits" by turning off the power, or if there's a
power cut or the computer simply fails, then your query will not run.
Obviously it'll run again when he next launches the application and shuts it
down properly (if he ever does!), but really it might be better to run your
query when the application *starts* rather then when it exits.
 
J

J.Bennett

Thanks! This works great. I actually had an opening splash screen that the
user must click on to close before proceeding so I set the code to run on
close of this form.
 
J

J.Bennett

Thanks. I incorporated your suggestion. I have an "Splash Screen" that opens
automatically that has disclaimers. The user must click on the screen before
moving on. I have the delete query run on close of this screen. It works
great. Thanks for the suggestion.
 

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