rohrl77
rohrl77

Reputation: 3337

How to Kill CurrentDB using self executed code

I have been researching ways to self execute code that would delete the current database file. I came across a code snippet here that does exactly that for Excel, but this does not seem to translate to Access very well.

 Sub KillMeExcel()
 With ThisWorkbook
    .Saved = True
    .ChangeFileAccess Mode:=xlReadOnly
    Kill .FullName
    .Close False
 End With
 End Sub

There does not seem to be a .ChangeFileAccess Mode in Access, so I haven't gotten further than that.

Is it possible to delete the current database using VBA code?

Upvotes: 1

Views: 448

Answers (2)

Andre
Andre

Reputation: 27634

I would also be wary of sending an open and running Access database via mail.

My workaround would be:

Launch an external vbs
DoCmd.Quit

and in the vbs:

  • Wait in a loop until the .ldb / .laccdb file is gone (i.e. the db is closed)
  • Send the mail with attached db
  • delete the db

Upvotes: 6

Gustav
Gustav

Reputation: 55816

That is not possible. You will get a Permission Denied error - for a reason.

Upvotes: 5

Related Questions