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

Can a macro delete a file?

Status
Not open for further replies.

lisaharris

Programmer
Feb 12, 2007
130
US
I have a macro that runs a detailed daily process -- it runs several queries to create three final output tables. Two of the tables may be empty.

Once the tables are created, they are exported in Excel format. I have a condition set for those two export lines so the empty tables won't export.

The problem is that if there is a file from the previous day, it will remain in the directory. I want the Macro to first delete the two excel files that may be in the output directory from the previous day.

VBA would be an acceptable alternative, I just need help with the code. Thanks for any ideas!

__________
Veni, Vidi, Visa: I came, I saw, I charged it.
 

Code:
[blue]Kill[/blue] "C:\TestFolder\SomeFile.xls"

Have fun.

---- Andy
 
lisaharris,
Andy's code will work for you but you will need to use vba if the name of the file chagnes every day change each day, ie, "Somefile_Dec_17_2010.xls".

With vba you'll be able to format a date to correctly construct a filename assuming the filename fits a regular, predictable naming convention.
--Jim
 
How do I issue the Kill command in a Macro using Access 2007? I've tried many different things and I can't figure this out.

__________
Veni, Vidi, Visa: I came, I saw, I charged it.
 
Kill is VBA, not macro.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

... but isn't a Macro written in Access VBA?

Where you can Run your macro, or Record a macro, you can also Edit a Macro, and that's where you should find the code for your macro. And that's where the Kill would go.

Post the code of your macro and someone will point the place for Kill to you.

Have fun.

---- Andy
 
Andy: it's different in Access.
There, there are macros and there are modules. The latter can contain VBA code.
You can also convert Access macros into VBA (via Tools menu), then you have access to your Access macro code.
[rednose]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
... but isn't a Macro written in Access VBA?

Where you can Run your macro, or Record a macro, you can also Edit a Macro, and that's where you should find the code for your macro. And that's where the Kill would go.

Andy - Access doesn't have a macro recorder like Excel or Word does. Macros in Access are a completely different thing as compared to Excel. VBA is separate from macros when it comes to Access.

Bob Larson
FORMER Microsoft Access MVP (2008-2009, 2009-2010)
Free Tutorials/Samples/Tools:
 
It's all working now. I placed the kill command in a VBA and set it as the "On Open" for an empty form. Then in the macro, I opened the form and immediately closed it. Works like a charm!

__________
Veni, Vidi, Visa: I came, I saw, I charged it.
 

Why an empty form?
In VBA, you can put:
Code:
DoCmd.RunMacro "YourMacro"
Crate a public function, something like:
Code:
Public Function KillMyFile()
    Kill "FilePath"
End Function
The macro:
Action: RunCode
Function Name: KllMyFile()



Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top