Solved

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

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

Expert Comment

by:Rey Obrero (Capricorn1)
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 35

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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

809 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