Solved

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

Posted on 2013-11-26
4
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 38

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

615 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