Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy directory files with VBA

Status
Not open for further replies.

smpayne

IS-IT--Management
Joined
Nov 3, 2004
Messages
1
Location
US
Is this possible?? I am doing this with a 3rd party macro right now, but would like it in VBA so I can run it directly from access prior to my queries:

Let>SourcePath=S:\CTV
Let>DestPath=\\MINT02\Share\SHARE\SMP\DialerRecon
Let>CF_OVERWRITE=1

Month>MM
Day>DD
Year>YYYY
MidStr>%YYYY%,3,2,YY
Let>FileName=%MM%%DD%%YY%pool55inv.txt
Let>NewFileName=pool55inv.txt


IfFileExists>%SourcePath%\%FileName%,CopyIt
MessageModal>File %Filename% was NOT found in %SourcePath%%CRLF%CRLF%No file copied. Process Stopped.
Goto>End

Label>CopyIt
CopyFile>%SourcePath%\%FileName%,%DestPath%\%NewFileName%

MessageModal>File %Filename% was found in %SourcePath%.%CRLF%%CRLF%. File was copied to %DestPath%.

IfFileExists>%DestPath%\%NewFileName%,Success,Fail

Label>Success
MessageModal>File Found
Goto>End

Label>Fail
MessageModal>File Not Found
Goto>End

Label>End

Is there anyway VBA can do the same procedure, and if so, would I be lucky enought to run into someone on here with a similar code already written?

I appreciate any help.
Shawn.
 
You can to do it using the FileSystemObject. In Tools/References, add a refernce to Microsoft Scripting Runtime. Then in your module add this:

Code:
Dim fso     As FileSystemObject
    
Set fso = New FileSystemObject
    
fso.CopyFolder ("S:\CTV","\\MINT02\Share\SHARE\SMP\DialerRecon",TRUE)

The TRUE flag will overwrite the folder if it already exists.

Hope this helps,

Patrick
 
You may gewt a better response by posting in an Access VBA forum rather than a Visual Basic forum. Try forum705.

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top