copy files between drives from within access 2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have just go a external hard drive and want to have a button in my Access
2003 switchboard (or a button on a form) that does the following:

copy files from c:\dw\ to n:\dw
if the file allready exists then overwrite if file on c: modofied more
recently than on H:

I don't know the first thing about vb/vba so I need some instructions for
dummies level help here.

I plan to have several buttons some will only backup a folder (and it's sub
folders)while one would back up several differant folders (and their sub
folders...)

Thank you for any assistance.
 
Darcy,

Add a command button to your form but don't take any of the options when if
prompts you, just click Finish.

Right click on the button and select Build Event.

It will open the VBA code window with the start and end of a procedure and it
should look something like this:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click


Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

After the "On Error statementment add this (or whatever you need):

Shell("xcopy c:\atempdir\*.* c:\dlink /D", vbHide)

The /D will only copy files from atempdir to dlink that don't exist in the
dlink folder or that have a newer date than the matching file name.

Save the form, click on the button. There are a dozen or so more parameters
for the xcopy command that can further refine what you need to do, just run a
cmd window and type in help xcopy.

Krazy said:
I have just go a external hard drive and want to have a button in my Access
2003 switchboard (or a button on a form) that does the following:

copy files from c:\dw\ to n:\dw
if the file allready exists then overwrite if file on c: modofied more
recently than on H:

I don't know the first thing about vb/vba so I need some instructions for
dummies level help here.

I plan to have several buttons some will only backup a folder (and it's sub
folders)while one would back up several differant folders (and their sub
folders...)

Thank you for any assistance.

--
Never let it be said that I was totally comitted to sanity. It is the dark
places of my mind that fascinate me.

NthDegree

Message posted via AccessMonster.com
 
Thanks.
Here is what I have at the moment

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

Shell("xcopy c:\dw\*.* H:\Dw /E", vbHide)

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.description
Resume Exit_Command1_Click

End Sub

I get a "Compile Error Syntax error" message when I click on the button on
the test form I am using to test it.

Also as soon as I finished typing the shell line I got a error message -
"Compile Error Expected "=" "

I havn't added the /d switch at the moment but added the /e switch (I
printed the xcopy /? output for referance) which tells it to copy
subdirectories

Thanks .
 
Shell is a function. When you use a function, you either need to assign its
value to a variable:

Dim lngReturn As Long

lngReturn = Shell("xcopy c:\dw\*.* H:\Dw /E", vbHide)

or, since you don't really care about what value it returns, Call the
function:

Call Shell("xcopy c:\dw\*.* H:\Dw /E", vbHide)

Another alternative is just to leave out the parentheses:

Shell "xcopy c:\dw\*.* H:\Dw /E", vbHide

but I personally prefer the Call syntax, as it makes it clearer that an
external routine is involved.
 
Thanks.
I'm getting no error messages now. And when I added "Call" to the line in
the code it changed from red to black.
It didn't seem to be doing anything so I removed the "vbhide" which ment a
command line window opened when I pushed the button. I can see why it still
isn't working - just a case of adding a switch ot two for xcopy. I have a
printout of the switches (via xcopy /? > xcopy.txt then print it out).

I should have the switches sorted tonight (NZST) after work. I'll post back
then as to how it goes.

Thanks for your time.
 
Thanks guys.

I clicked on did this post answer the question for both your answers but
unsure if it will appear that way as they combined answered my question

I used the following line

Call Shell("xcopy c:\dw\*.* n:\dw /d /e")

Which worked great.

/e means include subdirectories
I have removed vbhide as I want to see what is happening.
I may add
to it so that the cmd window output is sent to a text file

Thanks very much for your time from Wellington, New Zealand.
 
Back
Top