Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2005

Tip: Looking for answers? Try searching our database.

Move and deleting files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Justin - 14 Dec 2005 14:36 GMT
I need some assistance
I have this database that has to import 35 files everyday. NOw for checking
purpose, i have this code that once it imports all the files, it deletes all
files from that folder so user can't upload same files
I need to modify the code to first move the files first to a folder of my
choice and then delete. Please help

code:
Function DeleteFiles()
   Dim fso As New Scripting.FileSystemObject
   Dim fld As Scripting.Folder
   Dim fil As Scripting.File

   Set fld = fso.GetFolder([Forms]![Protobase Upload]![Pathtxt])

   For Each fil In fld.Files
         fil.Delete
   Next fil

   Set fso = Nothing
   Set fld = Nothing
   Set fil = Nothing

End Function
Douglas J. Steele - 14 Dec 2005 15:25 GMT
To move a file, you use the MoveFile method. There's a sample at
http://msdn.microsoft.com/library/en-us/script56/html/277621e8-9f65-4500-bc35-89
610894a3cf.asp


However, there's no real reason to use FSO for what you're trying to do. The
following uses strictly build-in VBA methods:

Function DeleteFiles()
   Dim strFile As String
   Dim strFolder As String
   Dim strTargetFolder As String

   strFolder = [Forms]![Protobase Upload]![Pathtxt]
   If Right(strFolder, 1) <> "\" Then
     strFolder = strFolder & "\"
  End If

  strTargetFolder = "C:\My Data\Imported Files\"

  strFile = Dir(strFolder & "*.*")
  Do While Len(strFile) > 0
     Name strFolder & strFile As strTargetFolder & strFile
     strFile = Dir()
  Loop

End Function

If strFolder and strTargetFolder aren't on the same drive, you can't use the
Name statement. In that case, you'll have to use FileCopy, and then delete
the file:

     FileCopy strFolder & strFile, strTargetFolder & strFile
     Kill strFolder & strFile

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

>I need some assistance
> I have this database that has to import 35 files everyday. NOw for
[quoted text clipped - 22 lines]
>
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.