Solved

Delete Contents of a folder in windows explorer from Access Database with code

Posted on 2013-11-26
4
362 Views
Last Modified: 2013-12-02
I have a folder called ZipSales Data. the path to the folder is  C:\ZipSales Data

On a monthly basis I open the folder and delete the contents. How can I delete all  the contents from access database with VBA code?
0
Comment
Question by:Conernesto
  • 2
4 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39678938
sub deleteFolderContent(FolderPath as string)

dim fso As Object
    Set fso = CreateObject("scripting.filesystemobject")
    on error resume next
    'Delete files
    fso.deletefile FolderPath & "\*.*", true

end sub


to use the sub, call it this way

deleteFolderContent "C:\ZipSales Data"
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39678979
I don't have any code handy but you can do this with the File System Object (FSO).  The code I have is way to complicated to paste here because it incorporates all sorts of stuff that you are not interested in.   Here's a link to the files collection to get you started.

http://msdn.microsoft.com/EN-US/library/office/gg251470.aspx
0
 

Author Comment

by:Conernesto
ID: 39679261
I created a module and copied the below code. When I run the code nothing happens or I get an error.


Option Compare Database
Option Explicit
Sub deleteFolderContent "C:\ZipSales Data" As String

Dim fso As Object
    Set fso = CreateObject("scripting.filesystemobject")
    On Error Resume Next
    'Delete files
    fso.deletefile FolderPath & "\*.*", True

End Sub


'to use the sub, call it this way

'deleteFolderContent "C:\ZipSales Data"
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39679469
that is not correct, copy and paste this


Option Compare Database
Option Explicit
Sub deleteFolderContent( FolderPath As String)

Dim fso As Object
    Set fso = CreateObject("scripting.filesystemobject")
    On Error Resume Next
    'Delete files
    fso.deletefile FolderPath & "\*.*", True

End Sub


'to use the sub, call it this way perhaps in the click event of a command button in a form

private sub command0_click()

deleteFolderContent "C:\ZipSales Data"

end sub
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now