Question Delete specific file

mcclunyboy

Registered User.
Local time
Today, 09:37
Joined
Sep 8, 2009
Messages
292
Hi,

I have a form that imports all the contents of a directory into a table. I can then view and open these files - most of this came from a sample database provided by this website - much obliged.

The form displays all the contents of the directory with a button to open the file. I would like a 2nd button to delete that specific file?

Can someone help?
 
Look at the Kill command

Kill PathToFile
 
thanks,

I actually just implemented it and it works fine. Now to find a refresh form one (so after the files deleted the form is refreshed to show it)
 
refreshing the form depends how you popluated the form.

you could either delete the same entry from the form's record source (eg the table or array, etc) - or requery the form again.
 
Thanks,

I ended up with the following - refresh/requery didn't cut it.
Code:
    Dim objFSO As Object
    'Create Instance of the File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Source file, Destination folder (must end with a backslash \)
    objFSO.CopyFile filepathname, "c:\newdir\", True
    
    'delete file from source directory
    Kill filepathname
    
    'close and reopen form
    DoCmd.Close acForm, "formname", acSaveYes
    DoCmd.OpenForm "formname"
 

Users who are viewing this thread

Back
Top Bottom