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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro To Make a file delete itself

Status
Not open for further replies.

davisto01

MIS
Jul 11, 2003
21
US
I have an excel sheet that is being generated daily by MS Access. I have searched about a dozen forums and no one seems to know how to bypass the 'overwrite' prompts access gives you.

Since the worst case scenario has reered its ugly head, I have decided that it might be effective to simply have the file delete itself after it opens (opens on a timer and sends a copy of itself by email)

Does anyone have a solution to either issue? (Especially the first one).
 
I'm assuming that Access VBA doesn't have an
Code:
Application.DisplayAlerts = False
function like Excel does.

If not, then I'm afraid I can't help you on the first problem.

The second problem is impossible from within the Excel File itself, but you can delete the file from the Access VBA:

add

Code:
Kill "C:\ExcelFile.xls"

after your code that sends the email.


Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Well, if you're just creating a new Excel file from Access every day and saving it as the same filename (overwriting yesterdays copy): delete yesterday's copy FIRST (using Mike's code), then create today's copy.

Kaboom - No annoying "Overwrite?" popup!

Let me know if this works for you.



VBAjedi [swords]
 
Hi davisto01,

If it helps, the Access equivalent of the Excel Application.DisplayAlerts is DoCmd.SetWarnings = False

Enjoy,
Tony
 
I've had this xl macro in my personal.xls for a while but never tested it so have a (careful) play

Sub Suicide()
'Workbook deletes itself
Dim KillShot As Integer
KillShot = MsgBox("Wanna kill this file?" & vbCrLf & "Be sure to make a backup if you change your mind later.", 36, "Feeling lucky?")
Select Case KillShot
Case 7
MsgBox "You live another day.", 64, "Spared the gallows, kill cancelled."
Exit Sub
Case 6
MsgBox "Click OK to flip the kill switch.", 48, "I hope you know what you're doing."
With ThisWorkbook
.Saved = True
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
End Select
End Sub

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top