Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-11-26
4
Medium Priority
?
416 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 39

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 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

715 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