Can file kill itself on close?

A

alex

Is there a way to program an mde to kill itself when it closes?

My application is setup so that a user uses a file that will copy an
mde to a specific location each and every time he/she wants to use the
application.

This works fine, but until the user wants to use the application
again, the mde just sits there taking up space.

I’d like the file to delete itself when it closes. I know you can use
the kill command to delete files; I’d like to code the file to do it
automatically when it closes.

The code would need to be in a module and not a form in case the user
did not use the form to close the mde (used the upper right X
instead).

It would also be nice if the file to check its location before the
kill occurred. Something like:

If file is in this location “C:\application_file\” Then
Kill “file”
Else
End If

Any thoughts?
Thanks,
alex
 
A

alex

Sorry, you can't delete a file that's in use.  It has a file lock on ituntil
the mde closes.

Chris

Thanks Chris for responding...
So it cannot delete itself after it closes!

How about deleting all linked tables when it closes/before it closes?
(I can post a new question if I need to)
thanks again,
alex
 
A

alex

No, the code inside the db isn't running after the db closes.

You can delete the linked tables as the db closes.  What's the purpose? It
won't save disk space and you'd have to relink the tables when the db opens
again.

Chris

Good question...
The purpose is this:

The user accesses the database with a simple mde (call it mde1) that
takes another mde (call it mde2) and copies it to a specific location
and then opens it.

The mde2 has all the forms, reports, and obviously linked tables.
When the user closes the database mde2 still resides on the user's
computer (which is why I wanted to delete it). Now, even though users
do not use the mde2 to access the database (they use mde1), a saavy/
curious user can use the shift bypass to open mde2 and view the data
contained in the linked tables. (Right now I hide mde2, but I may
need to unhide it for political reasons).

If we delete the links when mde2 closes, we've solved that problem.
We will not need to relink them because the next time the user wants
to use the database they use mde1 which copies a fresh mde2 (location
unknown to users) and opens it.

Does that make sense?
alex
 
A

alex

The savvy/curious user can't open mde2 with the shift key bypass if you apply
user level security to secure the table links, disable the shift key bypass
and require members of the admins group to reenable the shift key bypass.

Chris

User level security is a pain in the butt...
The shift bypass, however; is a good idea.

I've inquired about the shift bypass, but the code looked too
complicated. I hate putting code in my db when I don't know exactly
what it does.

Do you have simple code that eliminates the shift bypass. I've seen
the code to turn it on/off. What about code that only turns it off
(the bypass). Remember, we're only talking about a disposable mde!
When the user closes the db, the mde that accessed the backend is now
garbage. It will be replaced by a new one the next time the user
wants to view the db.
 
A

alex

If you do it right your users won't even know it's secured - until they try
to reenable the shift key bypass and find out they can't because they aren't
members of the admins group of a secure workgroup file they don't even know
about because you don't distribute it.

Chris

Thanks Chris, I'll take a look at it.
One final thing: can you share how to delete those links (just before
mde closes) we initially talked about?
I think I know how to do it in the close event of a form, but it needs
to be in global module in case the user exits another way.

Thanks again for your help/advice!
alex
 
K

Keven Denen

Thanks Chris, I'll take a look at it.
One final thing:  can you share how to delete those links (just before
mde closes) we initially talked about?
I think I know how to do it in the close event of a form, but it needs
to be in global module in case the user exits another way.

Thanks again for your help/advice!
alex

"I think I know how to do it in the close event of a form, but it
needs
to be in global module in case the user exits another way. "
..
You can do it in the Close event of the form and it will still work as
long as the form is open when your users close the database. The only
things that circumvents this is if the user Ctrl-Alt-Del and kills the
program. Make a form open on startup that has it's visible property
set to False. Put your code to cleanup when the database closes.

Keven Denen
 
A

alex

Put this code in a public function in a standard module:

Dim db As Database
Dim tdf As TableDef
Dim lngCnt As Long

Set db = CurrentDb
For lngCnt = db.TableDefs.Count - 1 To 0 Step -1
    Set tdf = db.TableDefs(lngCnt)
    If Len(tdf.Connect) > 0 Then
        db.TableDefs.Delete tdf.Name
    End If
Next lngCnt

Set tdf = nothing
Set db = nothing

Create a hidden form that opens on startup.  In the form's close event,call
the public function that deletes the table links.  When the user exits Access,
the form will close and execute the function, deleting all the linked tables
before finally closing the db.

Chris

Thanks again. It's always appreciated.

Chirs, not sure where you're at, but if it's still Sunday; enjoy the
rest of it.
alex
 

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