Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-13-2019, 05:01 AM   #1
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Clean-up map with pdf's

Hi everybody,

I like to clean up a map where I store my pdf's (copies of reports)

I would like to delete all the pdf's who are older than 6 months from "today's date" using the modified date and not the creation date.

The web didn't bring me any solution so far...

my pdf's are stored in : CurrentProject.Path & "\Verschilstaten - Decomptes - PDF"

Thanks in advance...

Greetz

Pascal

scallebe is offline   Reply With Quote
Old 09-13-2019, 05:14 AM   #2
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,396
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Clean-up map with pdf's

Code:
dim col As New Collection
dim sFile as string
dim sPath as string
dim i as long

sPath = CurrentProject.Path & "Verschilstaten - Decomptes - PDF\"
sFile = Dir(sPath & "*.pdf")
'save first before we delete
While sFile <> ""
    If DateValue(VBA.FileDateTime(sPath & sFile)) < DateAdd("m",-6 Date) Then
        col.Add sPath & sFile
    End If
    sFile = Dir
Wend
'we can delete it now
for i = 1 to col.Count
    VBA.Kill col(i)
next i
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-13-2019, 06:40 AM   #3
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Clean-up map with pdf's

arnelgp,

Thanks for reply,

I think your code is working with the creation date of the pdf. Because I copied the complete map to my working map at home, all these dates are the same. The code should run with the "modified at" date. See picture (=Dutch)

Knipsel.JPG

Thanks

Greetz

Pascal

scallebe is offline   Reply With Quote
Old 09-13-2019, 06:44 AM   #4
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,396
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Clean-up map with pdf's

check first the modified date of your file at explorer.
if modified date and creation date are same...?
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-13-2019, 06:53 AM   #5
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Clean-up map with pdf's

arnelgp,

No they are not, you can see the JPG I send.

The yellow dates are the modified dates, at the end you will see the creation date and they are all the same because of the copy yesterday.

I would like the code compere the modified date with today's date and delete all of them who are older than 6 months.

Thanks

Greetz

Pascal
scallebe is offline   Reply With Quote
Old 09-13-2019, 07:11 AM   #6
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,396
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Clean-up map with pdf's

Code:
Private Sub test()
    Dim fso As Object
    Dim oDir As Object
    Dim fil As Object
    Dim PDF_PATH As String
    Dim i As Long
    Dim col As New Collection
    PDF_PATH = CurrentProject.Path & "\Verschilstaten - Decomptes - PDF"
    Set fso = CreateObject("scripting.filesystemobject")
    Set oDir = fso.getfolder(PDF_PATH)
    For Each fil In oDir.Files
        If fil.name Like "*.pdf" Then
            If fil.DateLastModified > fil.DateCreated and _
                DateValue(fil.DateLastModified) < DateAdd("m", -6, Date) Then
                col.Add fil.Path
            End If
        End If
    Next
    Set fil = Nothing
    Set oDir = Nothing
    For i = 1 To col.count
        fso.deletefile col(i)
    Next
    Set fso = Nothing
End Sub
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-13-2019, 07:51 AM   #7
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Clean-up map with pdf's

Arnegp,

That's what I was looking for.

I don't know why you want to compere the DateLastModified with the DateCreated. In my experience I know for shure that this date never changes. Once the pdf is created that date never change. We can not modifi or edit a pdf at work...

So I left this line out : "fil.DateLastModified > fil.DateCreated And _"

and it works perfect. The first pdf I see now is from 03/13/2019.

Thank you so much…

See you next time

Greetz

Pascal

scallebe is offline   Reply With Quote
Old 09-13-2019, 07:54 AM   #8
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,396
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Clean-up map with pdf's

you're the boss, just do what is best.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-16-2019, 04:14 AM   #9
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Clean-up map with pdf's

Good afternoon arnelgp,

In #6 you set a code to clean-up my PDF-folder. Works perfect

I have a second pdf folder to clean-up the same way...

in following path :

Code:
CurrentProject.Path & "\Brieven Retour - Lettres retour - PDF"
How can I add the second folder into the code and do the clean-up in that folder to?

Thanks

Greetz

Pascal
scallebe is offline   Reply With Quote
Old 09-16-2019, 05:00 AM   #10
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,396
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Clean-up map with pdf's

Code:
Private Sub test()
    Dim fso As Object
    Dim oDir As Object
    Dim fil As Object
    Dim i As Long
    Dim j as integer
    Dim PDF_PATH As String
    Dim col As New Collection
    
    Dim arrPaths(1 To 2) As String
    
    arrPaths(1) = CurrentProject.Path & "\Verschilstaten - Decomptes - PDF"
    arrPaths(2) = CurrentProject.Path & "\Brieven Retour - Lettres retour - PDF"

    Set fso = CreateObject("scripting.filesystemobject")
    For j = 1 to Ubound(arrPaths)
        PDF_PATH = arrPaths(j)
        Set oDir = fso.getfolder(PDF_PATH)
        For Each fil In oDir.Files
            If fil.name Like "*.pdf" Then
                If DateValue(fil.DateLastModified) < DateAdd("m", -6, Date) Then
                    col.Add fil.Path
                End If
            End If
        Next
        Set fil = Nothing
        Set oDir = Nothing
        For i = 1 To col.count
            fso.deletefile col(i)
        Next
        Set col = New Collection
    Next j
    Set fso = Nothing
End Sub
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
The Following User Says Thank You to arnelgp For This Useful Post:
scallebe (09-16-2019)
Old 09-16-2019, 06:52 AM   #11
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Clean-up map with pdf's

arnelgp,

Thanks…

I am a little jealous of what you all realize as if it is nothing …

I also want to delve more into VBA, but time is not on my side at the moment...


Thanks again

Greetz

Pascal
scallebe is offline   Reply With Quote
Old 09-16-2019, 06:57 AM   #12
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,396
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Clean-up map with pdf's

there are lots of vba books out in the web (download for free, eg: Ebook777.com , https://sanet.st/full/, etc.)

__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
The Following User Says Thank You to arnelgp For This Useful Post:
scallebe (09-17-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Clean Code GBalcom Modules & VBA 4 09-28-2018 09:38 PM
[SOLVED] Clean data? Gasman Tables 10 12-23-2016 01:07 PM
Clean first names jpaokx Queries 11 03-01-2016 05:33 PM
Clean it up... Zippersabrat Modules & VBA 3 05-02-2014 09:59 AM
Clean Up onlyty General 2 08-15-2010 03:28 PM




All times are GMT -8. The time now is 07:07 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World