Solved

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

Posted on 2013-11-26
4
352 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 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

19 Experts available now in Live!

Get 1:1 Help Now